Skip to content

Instantly share code, notes, and snippets.

@scottmessinger
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottmessinger/9b31899898abfda45bef to your computer and use it in GitHub Desktop.
Save scottmessinger/9b31899898abfda45bef to your computer and use it in GitHub Desktop.
Data down observers
// 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