We’re attempting to debounce query parameters to implement a paginated live search using query-params-new
. We’re using the refreshModel: true
flag to indicate that we want to go back to the server when the param changes.
Here is a fiddle demonstrating that: emberjs.jsbin.com/qopacixi/1/edit
You’ll notice that it refreshes the model whenever the search param changes, as desired.
However, at some point you may want to debounce the model refresh from triggering to allow the user to type a more meaningful search before firing it off to your server.
Here is a fiddle demonstrating this: emberjs.jsbin.com/qejiloyu/2/edit
In order to get this to work we had to define a query parameter proxy that the template binds to, observe when it changes, and transition after a debounce. Is there an easier way to achieve this effect? If not, could there be another option to the route’s query params configuration (perhaps debounce: 1000
)? Or maybe a queryParamsWillChange
action (a la queryParamsDidChange
)?
And finally, when someone inputs a new search query, after we debounce we want to reset the page to 1.
Here is a fiddle where we do that: emberjs.jsbin.com/nitarezi/2/edit
Notice that we set the page back to 1 in the transitionToRoute - it would be nice if the aforementioned “hook” provided a place to mutate the query parameters before their changes are applied.
Anyone else doing things like this? Please share your experience.