Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.