Skip to content

BnitoBzh/ember-cli-debounce-query-params

Repository files navigation

Ember CLI Debounce Query Parameters

Build Status

This addon allows for updating queryParams with a defined debounce. It has been specifically designed to solve the following issue:

  1. You have a model you want to update when a query param changes;
  2. You don't want to update the history if the users is changing the param in a certain time interval;

A good example for this is a search input field, when you would like to update the results after the users have finished typing.

Installation

$ ember install ember-cli-debounce-query-params

Usage (Demo)

In your route-driven controller include the mixin and add the the debounceQueryParams property, like in the following example

// controllers/application.js
import Controller from '@ember/controller';
import DebounceQueryParamsMixin from 'ember-cli-debounce-query-params';

export default Controller.extend(DebounceQueryParamsMixin, {
  queryParams: ['search', 'filter'],

  search: null,
  filter: null,

  debounceQueryParams: {
    search: 500
  }
});

If you want to update the model the underneath model when the search param changes:

// controllers/application.js
import Route from '@ember/routing/route';

export default Route.extend({
  queryParams: {
    search: {
      refreshModel: true
    },
    filter: {
      replace: true
    }
  },

  model: function() {
    // retrieve your model here
  }
});

Then in your templates reference the debounced variables by prepending the debounce keyword, like in the following example

<h2>Welcome to Ember.js</h2>
<div>
  <label>search: {{input type='text' value=debounceSearch}}</label>
</div>

This addon consists only of a mixin that you can include in your route-driven controllers.

Running Tests

  • ember t
  • ember t -s

About

Ember CLI addon to update query params with a debounce.

Resources

License

Stars

Watchers

Forks

Packages

No packages published