Last active
June 14, 2017 21:15
-
-
Save chancancode/be94c92fe5b07405b9b475f4ad0febfb 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: '', | |
| github: service(), | |
| search: task(function * () { | |
| let { type, query } = this.getProperties('type', 'query'); | |
| console.log(`Searching ${type} for ${query}...`); | |
| yield timeout(Math.random() * 5000); | |
| let results = yield this.get('github').search(type, query); | |
| console.log(`Done searching ${type} for ${query}.`); | |
| return results.items; | |
| }).restartable(), | |
| results: computed('type', 'query', function() { | |
| return this.get('search').perform(); | |
| }), | |
| 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
| import Ember from 'ember'; | |
| const { inject: { service } } = Ember; | |
| export default Ember.Service.extend({ | |
| ajax: service(), | |
| search: function(type, query) { | |
| return this.get('ajax').request(`https://api.github.com/search/${type}?q=${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
| 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