You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

ember-query-params

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ember-query-params

Ember service for your query params


Version published
Weekly downloads
539
decreased by-40.77%
Maintainers
1
Install size
20.4 MB
Created
Weekly downloads
 

Readme

Source

ember-query-params

Ember service for your query params

:construction: Please use ember-parachute or ember-query-params-service instead.

NPM Build Status Ember Observer Score Ember Version

This addon is in response to https://github.com/emberjs/ember.js/issues/11592.
The idea came from Robert Jackson.

See the Changelog for version changes.

Compatibility

  • Ember.js v2.18 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

How It Works

Basically the idea is that there is a central service that stores all QP values and from which you can subscribe to QP changes.

We make this simple by providing a mixin for your route that sets up default QP values on the service from your controller, and hooks into the system for QP changes on URL updates. The controller also gets automatic subscriptions for all of it's own QPs.

You can also use the service yourself, i.e. paramsRelay: Ember.inject.service() anywhere else, and get access to setting, getting and subscribing to the QP changes.

Usage

Setup your route with the AutoSubscribe mixin so we can listen for changes in query params from the URL, and also setup automatic subscribes for all of the query params on the related controller.

// my-route.js
import Route from '@ember/routing/route';
import AutosubscribeMixin from 'ember-query-params/mixins/autosubscribe';

export default Route.extend(AutosubscribeMixin, {
  // If overriding `beforeModel`, make sure to call `this._super(...arguments)`.
  // Whatever else you have..
});

The AutoSubscribe mixin requires that your controller has queryParams array setup to start relaying query params to the paramsRelay service.

// my-controller.js
import Controller from '@ember/controller';

export default Controller.extend({
  queryParams: [
    'theme',
    { isSidebarOpen: 'sidebar' }
  ],
  isSidebarOpen: false,
  theme: 'default'
});

Service API

setParam

Function signature paramsRelay.setParam('name', value).

getParam

Function signature paramsRelay.getParam('name'). Returns the value, can be anything.

setParams

Function signature paramsRelay.setParams(obj).
A helper method to set many query params at once. Suggested usage includes using in the route, i.e. paramsRelay.setParams(this.paramsFor(this.routeName)).

hasParams

Function signature paramsRelay.hasParams().
Returns a boolean, letting you know if any params have been set on the service.

subscribe

Function signature paramsRelay.subscribe('name', (key, value) => { //do something });.

unsubscribe

Function signature paramsRelay.unsubscribe('name', sameFunctionUsedInSubscribe). The function you passed to subscribe must be the same one passed to unsubscribe to remove it from the list of callbacks to notify on change.

autoSubscribe

Function signature paramsRelay.autoSubscribe(this).
Where this is the controller that has a queryParams array. All default query param values from the controller are set on the paramsRelay service. All query params must have a unique name, since setting a 'theme' in one controller will set the same QP in another.

Custom Service

You can also setup your own service, just use the mixin.

import Service from '@ember/service';
import QPMixin from 'ember-query-params/mixins/query-params';

export default Service.extend(QPMixin, {
  // your code
});

Contributing

See CONTRIBUTING.md.

Keywords

FAQs

Package last updated on 13 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc