Giter Club home page Giter Club logo

ember-query-params-service's Introduction

ember-query-params-service

Build Status Maintainability Ember Observer Score npm

Compatibility

  • Ember.js v3.13 or above
  • Ember CLI v3.13 or above

Embroider support is available at ember 4.4 and higher

Installation

ember install ember-query-params-service

DISCLAIMER

This package is a work in progress and while it provides a more ergonomic way to access query params from anywhere in the app, there is still a dependency on controllers if you want to be able to link to routes with query params. This is due to an allow-list that's implemented in the route resolver.

RFC here: emberjs/rfcs#380

Also, this is an experiment, and SemVer guarantees cannot be assured (yet).

Usage

The @queryParam Decorator

Signature:

@queryParam: void;
@queryParam(param: string);
@queryParam(param: string, options: TransformOptions);
@queryParam(options: TransformOptions);

TransformOptions<T> = {
  defaultValue?: any;
  deserialize?: (param: string) => T;
  serialize?: (value: T) => string;
}

example:

import Route from '@ember/routing/route';
import { queryParam } from 'ember-query-params-service';

export default class ApplicationRoute extends Route {
  @queryParam isSpeakerNotes;
  @queryParam slideNumber;

  model() {
    return {
      isSpeakerNotes: this.isSpeakerNotes,
      slideNumber: this.slideNumber
    }
  }
}
{{this.model.isSpeakerNotes}} - {{this.model.slideNumber}}

optionally, an options hash may be passed to the decorator defining any of the three options, defaultValue, serialize, deserialize.

An example of using the default value would be:

import Component from "@glimmer/component";
import { queryParam } from "ember-query-params-service";

export default class SomeComponent extends Component {
  @queryParam({
    defaultValue: false,
  })
  active;

}

When the value is undefined, the defaultValue will be used when accessing the value

When the value is undefined or equal to the defaultValue, the param will not be present on the URL. In this way the URL will only contain params that are different than the default value.

An example of using serialize / deserialize would be:

import Component from "@glimmer/component";
import { queryParam } from "ember-query-params-service";

export default class SomeComponent extends Component {
  @queryParam({
    deserialize: (qp) =>  parseInt(( qp || '' ).replace(/-/g, '')),
    serialize: (value) => `-${value}-`,
  })
  foo;

   addToFoo() {
    this.foo = (this.foo || 0) + 1;
  }
}

this would not only allow numeric operations on the query param (whereas, by default, query params are all strings), but it also allows any sort of transform to occur between the queryParam in the URL and the property that you want to interact with.

Expanded usage with the service

import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';


export default class ApplicationRoute extends Route {
  @service queryParams;

  @alias('queryParams.current.r') isSpeakerNotes;
  @alias('queryParams.current.slide') slideNumber;

  model() {
    return {
      isSpeakerNotes: this.isSpeakerNotes,
      slideNumber: this.slideNumber
    }
  }
}

Setting Query Params

  • Directly on the service:

      @service queryParams;
    
      // ...somewhere
      this.queryParams.current.queryParamName = 'some value';

    and then the URL will show queryParamName=some%20value

  • or via the @alias decorator:

      @alias('queryParams.current.r') isSpeakerNotes;
    
      // ...somewhere
      this.isSpeakerNotes = false;

    and then the URL will show r=false

  • or via the @queryParam decorator:

      @queryParam isSpeakerNotes;
    
      // ...somewhere
      this.isSpeakerNotes = false;

    and then the URL will show isSpeakerNotes=false

  • or via the @queryParam decorator with renaming the param in the URL

      @queryParam('r') isSpeakerNotes;
    
      // ...somewhere
      this.isSpeakerNotes = false;

    and then the URL will show r=false

API

  • queryParams.current - the current set of query params for the currentURL

  • queryParams.byPath - query params for every route that has been visited since the last refresh

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

ember-query-params-service's People

Contributors

cah-brian-gantzler avatar ember-tomster avatar github-actions[bot] avatar nullvoxpopuli avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ember-query-params-service's Issues

Use RouteInfos

As of Ember 3.6.0 you know have access to the raw QPs on the RouteInfo. I don't think you need to parse out the params. I think you can just look at the transition.to on the transition which is a RouteInfo

Use route name instead of path when saving the query params in the cache.

For routes that have dynamic segments, the cache gets filled because the query params are store for each value of the dynamic segment. I would think that params should be tracked at the route level, not for each value of the dynamic segment.

Or should this be left as an optional feature that could be disabled. Should there be a config that say track params at Route or Path?

Pretty sure the original query params in the ember controller are at the route only

Assertion Failed: The options object passed to tracked() may only contain a 'value' or 'initializer' property, not both

Assertion Failed: The options object passed to tracked() may only contain a 'value' or 'initializer' property, not both. Received: [descriptor,key,kind,placement,initializer,toString].

ember 3.11.1

controller

export default Controller.extend({
  // dataSource: null,
  queryParams: ['page', 'sort'],
  page: null,
  sort: null

route

import Route from '@ember/routing/route';
import { queryParam } from 'ember-query-params-service';

export default class extends Route {
  @queryParam page;
  @queryParam sort;

NullVoxPopuli said

it's possible that ember-cli-babel is out of date, or that ember-query-params-service is using the wrong proposal spec

"ember-cli-babel": "^7.7.3",

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: undefined. Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

  • Update Node.js to v20.11.0
  • Update devDependencies (@arethetypeswrong/cli, @babel/core, @babel/eslint-parser, @babel/plugin-proposal-decorators, @babel/plugin-syntax-decorators, @babel/plugin-transform-private-methods, @babel/preset-typescript, @changesets/cli, @ember/test-helpers, @embroider/compat, @embroider/core, @embroider/test-setup, @embroider/webpack, @glint/core, @glint/environment-ember-loose, @glint/template, @nullvoxpopuli/eslint-configs, @rollup/plugin-babel, @rollup/plugin-node-resolve, @rollup/plugin-typescript, @tsconfig/ember, @types/qs, @types/qunit, @types/rsvp, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, concurrently, ember-auto-import, ember-cli, ember-cli-htmlbars, ember-source, ember-template-lint, eslint, eslint-config-prettier, eslint-plugin-ember, eslint-plugin-n, eslint-plugin-prettier, eslint-plugin-qunit, pnpm-sync-dependencies-meta-injected, publint, qunit, rollup, rollup-plugin-copy, tracked-built-ins, turbo, typescript, webpack)
  • Update pnpm to v8.14.1
  • Update devDependencies (major) (@embroider/addon-dev, @typescript-eslint/eslint-plugin, @typescript-eslint/parser, ember-cli-babel, ember-page-title, ember-qunit, ember-try, eslint-config-prettier, eslint-plugin-prettier, prettier, prettier-plugin-ember-template-tag, qunit-dom, rollup)
  • Update kategengler/put-built-npm-package-contents-on-branch action to v2
  • Lock file maintenance
  • Click on this checkbox to rebase all open PRs at once

Detected dependencies

github-actions
.github/workflows/ci.yml
  • wyvox/action v1
  • wyvox/action v1
  • wyvox/action v1
  • wyvox/action v1
  • wyvox/action v1
  • wyvox/action v1
.github/workflows/push-dist.yml
  • actions/checkout v4
  • NullVoxPopuli/action-setup-pnpm v2.3.1
  • kategengler/put-built-npm-package-contents-on-branch v1.0.0
.github/workflows/release.yml
  • wyvox/action v1
  • changesets/action v1
npm
dev/package.json
  • @babel/core ^7.22.9
  • @babel/eslint-parser ^7.22.9
  • @nullvoxpopuli/eslint-configs ^3.2.0
  • @typescript-eslint/eslint-plugin ^5.61.0
  • @typescript-eslint/parser ^5.61.0
  • eslint ^8.45.0
  • prettier ^2.8.8
  • typescript ^5.1.3
ember-query-params-service/package.json
  • @arethetypeswrong/cli ^0.7.0
  • @babel/core ^7.22.9
  • @babel/eslint-parser ^7.22.9
  • @babel/plugin-proposal-class-properties ^7.18.6
  • @babel/plugin-proposal-decorators ^7.22.7
  • @babel/plugin-proposal-object-rest-spread ^7.20.7
  • @babel/plugin-syntax-decorators ^7.22.5
  • @babel/plugin-transform-private-methods ^7.22.5
  • @babel/preset-typescript ^7.22.5
  • @embroider/addon-dev 3.2.0
  • @glimmer/component ^1.1.2
  • @glimmer/tracking ^1.1.2
  • @glint/core ^1.0.2
  • @glint/environment-ember-loose ^1.0.2
  • @glint/template ^1.0.2
  • @nullvoxpopuli/eslint-configs ^3.2.0
  • @rollup/plugin-babel ^6.0.3
  • @rollup/plugin-node-resolve ^15.1.0
  • @rollup/plugin-typescript ^11.1.2
  • @tsconfig/ember ^3.0.0
  • @types/qs ^6.9.7
  • @typescript-eslint/eslint-plugin ^5.61.0
  • @typescript-eslint/parser ^5.61.0
  • concurrently ^8.2.0
  • ember-modifier ^4.1.0
  • ember-source ~5.1.2
  • ember-template-lint ^5.11.1
  • eslint ^8.45.0
  • eslint-config-prettier ^8.3.0
  • eslint-plugin-ember ^11.10.0
  • eslint-plugin-node ^11.1.0
  • eslint-plugin-prettier ^5.0.0
  • prettier ^2.8.8
  • prettier-plugin-ember-template-tag ^0.3.2
  • publint ^0.1.16
  • rollup ~3.26.3
  • rollup-plugin-copy ^3.4.0
  • typescript ^5.1.6
package.json
  • @changesets/cli ^2.26.2
  • concurrently ^8.2.0
  • prettier ^2.8.8
  • prettier-plugin-ember-template-tag ^0.3.2
  • turbo ^1.10.9
  • node 20.10.0
  • pnpm 8.7.0
test-app/package.json
  • @babel/core ^7.22.9
  • @babel/eslint-parser ^7.22.9
  • @ember/optional-features ^2.0.0
  • @ember/string ^3.1.1
  • @ember/test-helpers ^3.2.0
  • @embroider/compat 3.2.0
  • @embroider/core 3.2.0
  • @embroider/test-setup ^3.0.1
  • @embroider/webpack 3.1.4
  • @glimmer/component ^1.1.2
  • @glimmer/tracking ^1.1.2
  • @glint/core ^1.0.2
  • @glint/environment-ember-loose ^1.0.2
  • @glint/template ^1.0.2
  • @nullvoxpopuli/eslint-configs ^3.2.0
  • @tsconfig/ember ^3.0.0
  • @types/qunit ^2.19.6
  • @types/rsvp ^4.0.4
  • @typescript-eslint/eslint-plugin ^5.61.0
  • @typescript-eslint/parser ^5.61.0
  • broccoli-asset-rev ^3.0.0
  • concurrently ^8.2.0
  • ember-auto-import 2.6.3
  • ember-cli ~5.1.0
  • ember-cli-app-version ^6.0.1
  • ember-cli-babel ^7.26.11
  • ember-cli-dependency-checker ^3.3.2
  • ember-cli-htmlbars ^6.2.0
  • ember-cli-inject-live-reload ^2.1.0
  • ember-cli-sri ^2.1.1
  • ember-cli-terser ^4.0.2
  • ember-disable-prototype-extensions ^1.1.3
  • ember-fetch ^8.1.2
  • ember-load-initializers ^2.1.2
  • ember-modifier ^4.1.0
  • ember-page-title ^7.0.0
  • ember-qunit ^7.0.0
  • ember-resolver ^11.0.0
  • ember-source ~5.1.2
  • ember-source-channel-url ^3.0.0
  • ember-template-lint ^5.11.1
  • ember-try ^2.0.0
  • eslint ^8.45.0
  • eslint-config-prettier ^8.8.0
  • eslint-plugin-ember ^11.10.0
  • eslint-plugin-n ^16.0.1
  • eslint-plugin-prettier ^4.2.1
  • eslint-plugin-qunit ^8.0.0
  • loader.js ^4.7.0
  • pnpm-sync-dependencies-meta-injected 0.0.8
  • prettier ^2.8.7
  • prettier-plugin-ember-template-tag ^0.3.2
  • qunit ^2.19.4
  • qunit-dom ^2.0.0
  • tracked-built-ins ^3.1.1
  • typescript ^5.1.6
  • webpack ^5.88.2

  • Check this box to trigger a request for Renovate to run again on this repository

Proposal for stickyness

By default all the params are sticky. Provide for an option to specify if a param should not be sticky.

Add an option (default to true if not specified)

{
   sticky: false
}

Create a method on the service

 reset(path);
 resetAll(path);

reset would set all the parameters on the passed path (current if no path passed) that are marked as sticky = false to their default values (undefined if no default value specified).

resetAll would set all the parameters on the passed path (current if no path passed) to their default values.

These methods would be called from somewhere on the controller, most likely resetController. At this time the consumer would have to opt in to actually creating the resetController hook and calling the reset method. Can look in the future for possibly making this an automatic call for all controllers.

Thoughts?

Weirdness of this decorator. Just some thoughts

Previous there was code like this

@queryParam a = 1;

Which set the value the initial value to one, not really the default value in terms of query params.

Now we have this

@queryParam({defaultValue: 1}) a;

But if you were to do this

@queryParam({defaultValue: 1}) a = 2;

A doesnt get set to 2, because of the way default value works. I dont think you would ever really do this as it kinda defeats the purpose of the default. Think we are ok there.

Now you could do this

@queryParam({defaultValue: 1}) a;

constructor() {
   super(...arguments);
   this.a = 2;
}

And that actually works, a is 2, because the QueryParamHandler.set got called. This however only works in a component. If you put the above code in a controller for a child route (not application as you have in the dummy app), things get weird. The application is currently showing the root path of / but ember is pre instantiating controllers since they are singletons which means the controller constructor gets fired when the wrong route than intended is current. (Does that make sense?) The gotcha is dont set query param values in the constructor of a controller (or specifically singleton. ie what if someone uses this decorator in a service or a route )

The decorator as designed is not tied to a specific route at all, its what ever is current. We should probably make this a lot more clear in the read me to help avoid this nuances.

Just talking now, not purposing.... If we switch to route name instead of path, I guess we could add a routeName to the options, then only set if that route is the current route, what about get, defaultValue or maybe undefined if correct route isnt current. Solves problems but causes a maintenance problem. The decorator is re-run every time the component is on the screen so we could do some things there, but only run once on singletons so wouldnt work all the time.

Just some thoughts. Any comments?

TypeError: Cannot read property 'name' of null ---- at QueryParamsService.updateURL

I have the following routes:

application/route.js (defines queryParam preCheck)
application/controll.js (defines alias queryParams.current.preCheck)
master/route.js (defines queryParam search)
master/controller (defined alias for queryParam queryParams.current.search)

Both routes have the same path: '/'

When I load the page, it throughs the following error:

TypeError: Cannot read property 'name' of null
    at QueryParamsService.updateURL (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/addon-tree-output/ember-query-params-service/services/query-params.js:66:1)
    at RouterService.router.on.transition (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/addon-tree-output/ember-query-params-service/services/query-params.js:34:1)
    at sendEvent (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/metal.js:463:1)
    at RouterService.trigger (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/runtime/lib/mixins/evented.js:110:1)
    at Class._router.on.transition (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/routing/lib/services/router.js:71:1)
    at sendEvent (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/metal.js:463:1)
    at Class.trigger (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/runtime/lib/mixins/evented.js:110:1)
    at PrivateRouter.routeWillChange (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/routing/lib/system/router.js:179:1)
    at Transition.abort (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/router_js.js:366:1)
    at PrivateRouter.transitionDidError (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/@ember/-internals/routing/lib/system/router.js:209:1)
    at Transition.promise.state.resolve.catch.result (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/router_js.js:270:1)
    at invokeCallback (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/rsvp.js:490:1)
    at publish (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/rsvp.js:473:1)
    at publishRejection (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/rsvp.js:409:1)
    at _runloop.backburner.schedule (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/ember-testing/lib/ext/rsvp.js:16:1)
    at invokeWithOnError (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/backburner.js:344:1)
    at Queue.flush (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/backburner.js:226:1)
    at DeferredActionQueues.flush (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/backburner.js:423:1)
    at Backburner._end (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/backburner.js:957:1)
    at Backburner._boundAutorunEnd (/var/folders/gv/h8f0csq173j19t15l_y9zfmm0000gn/T/broccoli-30947kl9I5HEIGpUt/out-655-append_ember_auto_import_analyzer/assets/backburner.js:626:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)

If I try to use preCheck it works just fine.
NOTE: it's in the application route

If I try to reference query param search from both router and controller, I get the error.
If I don't use it in either router or controller, it works just fine.
NOTE: it's in the "nested" master route, which is under application route.

What are the chances that we can't use queryParam from both router and controller in nested routes?

UPDATE:

After some debugging of the addon, looks like it fails as the transition.from and transition.to are both null and that makes sense as I'm loading the route for the first time.
But the error message is saying that "same query param" cannot be refered from both router and controller:

router.js:1211 Error while processing route: application.master Assertion Failed: You're not allowed to have more than one controller property map to the same query param key, but both `application:__INIT_WAS_CALLED__ember15706556339071062844181561__` and `application.master:__INIT_WAS_CALLED__ember15706556339071062844181561__` map to `__INIT_WAS_CALLED__ember15706556339071062844181561__`. You can fix this by mapping one of the controller properties to a different query param key via the `as` config option, e.g. `__INIT_WAS_CALLED__ember15706556339071062844181561__: { as: 'other-__INIT_WAS_CALLED__ember15706556339071062844181561__' }` 
    at assert (http://localhost:4200/assets/vendor.js:37145:15)
    at Class._queryParamsFor (http://localhost:4200/assets/vendor.js:24476:54)
    at forEachQueryParam (http://localhost:4200/assets/vendor.js:25099:26)
    at Class._deserializeQueryParams (http://localhost:4200/assets/vendor.js:24289:7)
    at getFullQueryParams (http://localhost:4200/assets/vendor.js:22925:12)
    at getQueryParamsFor (http://localhost:4200/assets/vendor.js:22938:27)
    at Class.paramsFor (http://localhost:4200/assets/vendor.js:21466:25)
    at Class._paramsFor (http://localhost:4200/assets/vendor.js:23582:23)
    at Class.deserialize (http://localhost:4200/assets/vendor.js:22304:30)
    at http://localhost:4200/assets/vendor.js:90041:81

operation is null

Hi there,

I tried to install (yarn add ember-query-params-service) and import something (import { queryParams } from 'ember-query-params-service';) but I'm getting operation is null and Error: Could not find module 'ember-query-params-service' imported from labs-zap-search/components/projects-map-data`.

package.json:

    "ember-query-params-service": "github:NullVoxPopuli/ember-query-params-service",
    "ember-source": "~3.3.1",

Serialize and deserialize are not called

I'm running ember-source 3.26.1. When using the @QueryParam decorator the serialization options are not being called.

  @queryParam("myQP", {
    deserialize: function(qp) {
      console.log("deserialize", qp);
      return JSON.parse(qp)
    },
    serialize: function (value) {
      debugger;
      console.log("serialize", value);
      return JSON.stringify(value)
    }
  })
  myQP;

Any update to the query parameter does not log this.

[Security] Workflow tests.yml is using vulnerable action wagoid/commitlint-github-action

The workflow tests.yml is referencing action wagoid/commitlint-github-action using references v3. However this reference is missing the commit bf83d2b35c4177779d047f464b48d9907f2c5201 which may contain fix to the some vulnerability.
The vulnerability fix that is missing by actions version could be related to:
(1) CVE fix
(2) upgrade of vulnerable dependency
(3) fix to secret leak and others.
Please consider to update the reference to the action.

Proposal for query param default value

As currently implemented, the default value is more an initial value. I would like the query params to treat the default value as a more true default value. If the current value is the default value, the query param should not appear on the URL.

Proposed implementation

@queryParam({
   defaultValue: true
})

allow setting the default value in the same options hash that the serialize/deserialize use.

Notes:
The default value is set as a string as it may make it easier in the code. While writing the code this may be removed and allow for just the value true. Code does support native values
The default value may not easily be set dynamically. When writing the code will see what can be done about this.

Suggestion: Should the query params be sorted when added to the URL

As I was messing with query params the new ones I added were at the end of the URL, I was wondering if we should sort them prior to adding them the to the url for consistency. Ember Data does this so they are always in the same order for browser to see they have been previous cached. Different problem but for consumer reading, just wondered.

Any thoughts?

We add out query params to existing in some cases, I would assume we should sort the existing into ours rather than leave them seperate

Error after redirect

This issue happens, when I open a route with a component on it using the @QueryParam decorator, all works fine, until I navigate away from that route, to a route with a dynamic segment, (it can even be that I first navigate to a route without a dynamic segment, works fine, and then navigate to a route with a dynamic segment, causing the issue).

If I refresh the browser, and navigate to all the same routes except for the route with the query params component on it, all is dandy, no issues.

I've made an example application to reproduce the error.
Source
Hosted application

The error below you get after navigating to a route with a Query Params component directly to a route with a dynamic component (In the example app, navigate to: Route with Query Param then afterwards click Dynamic 1 immediately)

These are the stack traces i'm getting
router_js.js:1035 Uncaught (in promise) TypeError: Cannot read property 'shouldSupercede' of undefined
    at NamedTransitionIntent.applyToHandlers (router_js.js:1035)
    at NamedTransitionIntent.applyToState (router_js.js:982)
    at PrivateRouter.generate (router_js.js:1865)
    at Class.generate (router.js:493)
    at RouterService.urlFor (router.js:256)
    at QueryParamsService.updateURL (query-params.js:144)
    at RouterService.<anonymous> (query-params.js:100)
    at sendEvent (index.js:142)
    at RouterService.trigger (evented.js:107)
    at Class.<anonymous> (router.js:88)

and

The error below you get after navigating to a route with a Query Params component to the parent route of a dynamic route, and then to a dynamic route:

(In the example app, navigate to: Route with Query Param then afterwards click Dynamic Index and afterwards Dynamic 1)

Uncaught (in promise) Error: You must provide param `id` to `generate`.
    at getParam (route-recognizer.js:137)
    at Array.generate.<computed> (route-recognizer.js:183)
    at RouteRecognizer.generate$1 [as generate] (route-recognizer.js:553)
    at PrivateRouter.generate (router_js.js:1873)
    at Class.generate (router.js:493)
    at RouterService.urlFor (router.js:256)
    at QueryParamsService.updateURL (query-params.js:144)
    at RouterService.<anonymous> (query-params.js:100)
    at sendEvent (index.js:142)
    at RouterService.trigger (evented.js:107)
I've found some similar bugs online, about the shouldSupercede function, causing some issues in combination with the link-to helper and multiple dynamic segments in a route, but i'm not using link-to anywhere (using href-to instead), and none of my routes have multiple dynamic segments

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.