Forked from mike-north/components.my-component.js
Last active
September 5, 2018 07:34
-
-
Save HenryVonfire/8017fec1a6c2991811b2007c5edf2bcd to your computer and use it in GitHub Desktop.
component-data-provider
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'; | |
// it makes the issue of async really simple, in that you just care about the array {{my-component}} yields out | |
// it may at some times be empty, it may have some stuff later -- you're just binding to it. No promises for you to worry about | |
// you could do the same thing with the API call currently in your controller, and then break out code that consumes that data into other components. | |
// to make this even fancier, you could add Ember.run.debounce to avoid race conditions | |
export default Ember.Component.extend({ | |
term: '', | |
init() { | |
this._super(...arguments); | |
this.set('results', []); | |
}, | |
didReceiveAttrs() { | |
this._super(...arguments); | |
this.getSearchResults(); | |
}, | |
getSearchResults() { | |
fetch('https://api.mike.works/api/v1/search?types=course&q=' + this.get('term')) | |
.then(response => response.json()) | |
.then(responseData => { | |
this.get('results').setObjects(responseData); | |
}); | |
} | |
}); |
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', | |
searchTerm: 'node' | |
}); |
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.15.0", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.2.2", | |
"ember-template-compiler": "3.2.2", | |
"ember-testing": "3.2.2" | |
}, | |
"addons": { | |
"ember-data": "3.2.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment