Last active
June 16, 2017 18:51
-
-
Save chancancode/4adde6ca35c70ee3ae57e8a10cf55176 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'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
query: '', | |
actions: { | |
doSearch(query) { | |
this.replaceRoute('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'; | |
import { task, timeout } from 'ember-concurrency'; | |
const { computed, inject: { service } } = Ember; | |
export default Ember.Controller.extend({ | |
queryParams: ['query'], | |
query: '', | |
ajax: service(), | |
search: task(function * (type, query) { | |
console.log(`Searching ${type} for ${query}...`); | |
yield timeout(Math.random() * 5000); | |
let result = yield this.get('ajax').request(`https://api.github.com/search/${type}?q=${query}`); | |
console.log(`Done searching ${type} for ${query}.`); | |
return result.items; | |
}), | |
userSearch: computed('query', function() { | |
let query = this.get('query'); | |
return this.get('search').perform('users', query); | |
}), | |
repoSearch: computed('query', function (){ | |
let query = this.get('query'); | |
return this.get('search').perform('repositories', 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'; | |
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'; | |
export default Ember.Route.extend({ | |
queryParams: { | |
query: { refreshModel: true } | |
}, | |
model(params) { | |
return params.query; | |
}, | |
activate() { | |
let query = this.modelFor('search'); | |
this.controllerFor('application').set('query', query); | |
}, | |
deactivate() { | |
this.controllerFor('application').set('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