Last active
June 14, 2017 20:50
-
-
Save chancancode/120b6257785d077cda253aa5963ba582 to your computer and use it in GitHub Desktop.
New Twiddle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import { task, timeout } from 'ember-concurrency'; | |
const { computed, inject: { service } } = Ember; | |
export default Ember.Component.extend({ | |
type: null, | |
query: '', | |
ajax: service(), | |
search: task(function * (){ | |
let { type, query } = this.getProperties('type', 'query'); | |
let result = yield this.get('ajax').request(`https://api.github.com/search/${type}?q=${query}`); | |
return result.items; | |
}).on('init') | |
.observes('type', 'query') | |
.restartable(), | |
displayProperty: computed('type', function (){ | |
let type = this.get('type'); | |
switch(type) { | |
case "users": | |
return "login"; | |
case "repositories": | |
return "full_name"; | |
default: | |
return "id"; | |
} | |
}) | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
actions: { | |
doSearch(query) { | |
this.transitionToRoute('search', { queryParams: { query } }); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
queryParams: ['query'], | |
query: null | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
import config from './config/environment'; | |
const Router = Ember.Router.extend({ | |
location: 'none', | |
rootURL: config.rootURL | |
}); | |
Router.map(function() { | |
this.route('search'); | |
}); | |
export default Router; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 62px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
header { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
height: 50px; | |
background: #efefef; | |
padding: 0; | |
margin: 0; | |
} | |
header > * { | |
display: inline-block; | |
height: 50px; | |
line-height: 50px; | |
font-size: 24px; | |
padding: 0 16px; | |
margin: 0; | |
} | |
header > .search { | |
float: right; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.12.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.12.0", | |
"ember-template-compiler": "2.12.0", | |
"ember-testing": "2.12.0" | |
}, | |
"addons": { | |
"ember-ajax": "*", | |
"ember-concurrency": "*", | |
"ember-data": "2.12.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment