npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ember-query-params

v2.1.2

Published

Ember service for your query params

Downloads

4,133

Readme

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.