Last active
August 29, 2015 14:24
-
-
Save scottmessinger/9b31899898abfda45bef to your computer and use it in GitHub Desktop.
Data down observers
This file contains 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
// SearchController | |
export default Ember.Controller.extend({ | |
queryParams: ['query'] | |
}) | |
// SearchController template | |
{{x-search query=query}} | |
// X-Search component | |
export default Ember.Component.extend({ | |
// What I want (but won't work because CPs won't | |
// work unless they're called by the template. | |
onQueryChange: Ember.computed('query', function(){ | |
// do ajax call to seach service | |
// .then(data => {this.set('results', data) | |
}, | |
layout: hbs` | |
{{input value=query}} | |
{{#each results as |result|} | |
{{result}} | |
{{/each}} | |
` | |
}) | |
// Because the above won't work, I'm using the `key-up` action from the input to | |
// call the search function. Also, on `didInsertElement`, I'm calling the search | |
// function. I'd prefer to update the URL and only run the search function when | |
// the URL (query param) changes. That way, if the query updates outside of the | |
// `input` tag, the search function will still run. | |
// Thinking more broadly, what I really want is the data-down flow, but I want | |
// to trigger actions other than template rerenders. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment