├── app └── .gitkeep ├── vendor └── .gitkeep ├── tests ├── integration │ └── .gitkeep ├── dummy │ ├── app │ │ ├── helpers │ │ │ └── .gitkeep │ │ ├── models │ │ │ └── .gitkeep │ │ ├── styles │ │ │ └── app.css │ │ ├── components │ │ │ └── .gitkeep │ │ ├── templates │ │ │ ├── components │ │ │ │ └── .gitkeep │ │ │ ├── route-with-query-params-reset.hbs │ │ │ ├── route-without-query-params-reset.hbs │ │ │ └── index.hbs │ │ ├── resolver.js │ │ ├── routes │ │ │ └── route-with-query-params-reset.js │ │ ├── controllers │ │ │ ├── route-with-query-params-reset.js │ │ │ └── route-without-query-params-reset.js │ │ ├── router.js │ │ ├── app.js │ │ └── index.html │ ├── config │ │ ├── optional-features.json │ │ ├── targets.js │ │ └── environment.js │ └── public │ │ └── robots.txt ├── test-helper.js ├── helpers │ └── create-route.js ├── acceptance │ ├── route-with-query-params-reset-test.js │ └── route-without-query-params-reset-test.js ├── index.html └── unit │ ├── mixins │ └── query-params-reset-route-test.js │ └── utils │ └── reset-query-params-test.js ├── .watchmanconfig ├── .template-lintrc.js ├── index.js ├── config ├── environment.js └── ember-try.js ├── .ember-cli ├── .eslintignore ├── addon ├── mixins │ └── query-params-reset-route.js └── utils │ └── reset-query-params.js ├── .editorconfig ├── .gitignore ├── .npmignore ├── ember-cli-build.js ├── testem.js ├── CONTRIBUTING.md ├── LICENSE.md ├── .eslintrc.js ├── .travis.yml ├── package.json └── README.md /app/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /vendor/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/integration/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/helpers/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/models/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/styles/app.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/components/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/components/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | { 2 | "ignore_dirs": ["tmp", "dist"] 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/config/optional-features.json: -------------------------------------------------------------------------------- 1 | { 2 | "jquery-integration": false 3 | } 4 | -------------------------------------------------------------------------------- /tests/dummy/public/robots.txt: -------------------------------------------------------------------------------- 1 | # http://www.robotstxt.org 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /.template-lintrc.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | extends: 'recommended' 5 | }; 6 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | name: require('./package').name 5 | }; 6 | -------------------------------------------------------------------------------- /tests/dummy/app/resolver.js: -------------------------------------------------------------------------------- 1 | import Resolver from 'ember-resolver'; 2 | 3 | export default Resolver; 4 | -------------------------------------------------------------------------------- /config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(/* environment, appConfig */) { 4 | return { }; 5 | }; 6 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/route-with-query-params-reset.hbs: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 | {{link-to "Back" "index"}} 9 |
-------------------------------------------------------------------------------- /tests/dummy/app/templates/route-without-query-params-reset.hbs: -------------------------------------------------------------------------------- 1 |
2 | 5 |
6 | 7 |
8 | {{link-to "Back" "index"}} 9 |
-------------------------------------------------------------------------------- /tests/dummy/app/routes/route-with-query-params-reset.js: -------------------------------------------------------------------------------- 1 | import Route from '@ember/routing/route'; 2 | import QueryParamsResetRouteMixin from 'ember-query-params-reset/mixins/query-params-reset-route'; 3 | 4 | export default Route.extend(QueryParamsResetRouteMixin); 5 | -------------------------------------------------------------------------------- /tests/test-helper.js: -------------------------------------------------------------------------------- 1 | import Application from '../app'; 2 | import config from '../config/environment'; 3 | import { setApplication } from '@ember/test-helpers'; 4 | import { start } from 'ember-qunit'; 5 | 6 | setApplication(Application.create(config.APP)); 7 | 8 | start(); 9 | -------------------------------------------------------------------------------- /.ember-cli: -------------------------------------------------------------------------------- 1 | { 2 | /** 3 | Ember CLI sends analytics information by default. The data is completely 4 | anonymous, but there are times when you might want to disable this behavior. 5 | 6 | Setting `disableAnalytics` to true will prevent any data from being sent. 7 | */ 8 | "disableAnalytics": false 9 | } 10 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | # unconventional js 2 | /blueprints/*/files/ 3 | /vendor/ 4 | 5 | # compiled output 6 | /dist/ 7 | /tmp/ 8 | 9 | # dependencies 10 | /bower_components/ 11 | /node_modules/ 12 | 13 | # misc 14 | /coverage/ 15 | !.* 16 | 17 | # ember-try 18 | /.node_modules.ember-try/ 19 | /bower.json.ember-try 20 | /package.json.ember-try 21 | -------------------------------------------------------------------------------- /addon/mixins/query-params-reset-route.js: -------------------------------------------------------------------------------- 1 | import Mixin from '@ember/object/mixin'; 2 | import resetQueryParams from '../utils/reset-query-params'; 3 | 4 | export default Mixin.create({ 5 | resetController(controller, isExiting) { 6 | if (isExiting) { 7 | resetQueryParams(this); 8 | } 9 | 10 | this._super(...arguments); 11 | } 12 | }); 13 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/route-with-query-params-reset.js: -------------------------------------------------------------------------------- 1 | import Controller from '@ember/controller'; 2 | import { set } from '@ember/object'; 3 | 4 | export default Controller.extend({ 5 | queryParams: ['aParam'], 6 | aParam: false, 7 | 8 | actions: { 9 | addQueryParam() { 10 | set(this, 'aParam', true); 11 | } 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /tests/dummy/app/controllers/route-without-query-params-reset.js: -------------------------------------------------------------------------------- 1 | import Controller from '@ember/controller'; 2 | import { set } from '@ember/object'; 3 | 4 | export default Controller.extend({ 5 | queryParams: ['aParam'], 6 | aParam: false, 7 | 8 | actions: { 9 | addQueryParam() { 10 | set(this, 'aParam', true); 11 | } 12 | } 13 | }); 14 | -------------------------------------------------------------------------------- /tests/dummy/app/templates/index.hbs: -------------------------------------------------------------------------------- 1 |
2 | {{link-to 3 | "route-without-query-params-reset" 4 | "route-without-query-params-reset" 5 | id="route-without-query-params-reset" 6 | }} 7 |
8 |
9 | {{link-to 10 | "route-with-query-params-reset" 11 | "route-with-query-params-reset" 12 | id="route-with-query-params-reset" 13 | }} 14 |
-------------------------------------------------------------------------------- /tests/dummy/config/targets.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const browsers = [ 4 | 'last 1 Chrome versions', 5 | 'last 1 Firefox versions', 6 | 'last 1 Safari versions' 7 | ]; 8 | 9 | const isCI = !!process.env.CI; 10 | const isProduction = process.env.EMBER_ENV === 'production'; 11 | 12 | if (isCI || isProduction) { 13 | browsers.push('ie 11'); 14 | } 15 | 16 | module.exports = { 17 | browsers 18 | }; 19 | -------------------------------------------------------------------------------- /tests/dummy/app/router.js: -------------------------------------------------------------------------------- 1 | import EmberRouter from '@ember/routing/router'; 2 | import config from './config/environment'; 3 | 4 | const Router = EmberRouter.extend({ 5 | location: config.locationType, 6 | rootURL: config.rootURL 7 | }); 8 | 9 | Router.map(function() { 10 | this.route('route-without-query-params-reset'); 11 | this.route('route-with-query-params-reset'); 12 | }); 13 | 14 | export default Router; 15 | -------------------------------------------------------------------------------- /tests/dummy/app/app.js: -------------------------------------------------------------------------------- 1 | import Application from '@ember/application'; 2 | import Resolver from './resolver'; 3 | import loadInitializers from 'ember-load-initializers'; 4 | import config from './config/environment'; 5 | 6 | const App = Application.extend({ 7 | modulePrefix: config.modulePrefix, 8 | podModulePrefix: config.podModulePrefix, 9 | Resolver 10 | }); 11 | 12 | loadInitializers(App, config.modulePrefix); 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | end_of_line = lf 10 | charset = utf-8 11 | trim_trailing_whitespace = true 12 | insert_final_newline = true 13 | indent_style = space 14 | indent_size = 2 15 | 16 | [*.hbs] 17 | insert_final_newline = false 18 | 19 | [*.{diff,md}] 20 | trim_trailing_whitespace = false 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist/ 5 | /tmp/ 6 | 7 | # dependencies 8 | /bower_components/ 9 | /node_modules/ 10 | 11 | # misc 12 | /.sass-cache 13 | /connect.lock 14 | /coverage/ 15 | /libpeerconnection.log 16 | /npm-debug.log* 17 | /testem.log 18 | /yarn-error.log 19 | 20 | # ember-try 21 | /.node_modules.ember-try/ 22 | /bower.json.ember-try 23 | /package.json.ember-try 24 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # compiled output 2 | /dist/ 3 | /tmp/ 4 | 5 | # dependencies 6 | /bower_components/ 7 | 8 | # misc 9 | /.bowerrc 10 | /.editorconfig 11 | /.ember-cli 12 | /.eslintignore 13 | /.eslintrc.js 14 | /.gitignore 15 | /.template-lintrc.js 16 | /.travis.yml 17 | /.watchmanconfig 18 | /bower.json 19 | /config/ember-try.js 20 | /CONTRIBUTING.md 21 | /ember-cli-build.js 22 | /testem.js 23 | /tests/ 24 | /yarn.lock 25 | .gitkeep 26 | 27 | # ember-try 28 | /.node_modules.ember-try/ 29 | /bower.json.ember-try 30 | /package.json.ember-try 31 | -------------------------------------------------------------------------------- /ember-cli-build.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); 4 | 5 | module.exports = function(defaults) { 6 | let app = new EmberAddon(defaults, { 7 | // Add options here 8 | }); 9 | 10 | /* 11 | This build file specifies the options for the dummy test app of this 12 | addon, located in `/tests/dummy` 13 | This build file does *not* influence how the addon or the app using it 14 | behave. You most likely want to be modifying `./index.js` or app's build file 15 | */ 16 | 17 | return app.toTree(); 18 | }; 19 | -------------------------------------------------------------------------------- /testem.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | test_page: 'tests/index.html?hidepassed', 3 | disable_watching: true, 4 | launch_in_ci: [ 5 | 'Chrome' 6 | ], 7 | launch_in_dev: [ 8 | 'Chrome' 9 | ], 10 | browser_args: { 11 | Chrome: { 12 | ci: [ 13 | // --no-sandbox is needed when running Chrome inside a container 14 | process.env.CI ? '--no-sandbox' : null, 15 | '--headless', 16 | '--disable-gpu', 17 | '--disable-dev-shm-usage', 18 | '--disable-software-rasterizer', 19 | '--mute-audio', 20 | '--remote-debugging-port=0', 21 | '--window-size=1440,900' 22 | ].filter(Boolean) 23 | } 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How To Contribute 2 | 3 | ## Installation 4 | 5 | * `git clone ` 6 | * `cd ember-query-params-reset` 7 | * `npm install` 8 | 9 | ## Linting 10 | 11 | * `npm run lint:hbs` 12 | * `npm run lint:js` 13 | * `npm run lint:js -- --fix` 14 | 15 | ## Running tests 16 | 17 | * `ember test` – Runs the test suite on the current Ember version 18 | * `ember test --server` – Runs the test suite in "watch mode" 19 | * `ember try:each` – Runs the test suite against multiple Ember versions 20 | 21 | ## Running the dummy application 22 | 23 | * `ember serve` 24 | * Visit the dummy application at [http://localhost:4200](http://localhost:4200). 25 | 26 | For more information on using ember-cli, visit [https://ember-cli.com/](https://ember-cli.com/). -------------------------------------------------------------------------------- /tests/helpers/create-route.js: -------------------------------------------------------------------------------- 1 | import EmberObject from '@ember/object'; 2 | import QueryParamsResetRouteMixin from 'ember-query-params-reset/mixins/query-params-reset-route'; 3 | 4 | const QueryParamsResetRoute = EmberObject.extend(QueryParamsResetRouteMixin); 5 | 6 | export default function createRoute() { 7 | let controller = EmberObject.create({ 8 | myParam1: 'test value 1', 9 | myParam2: 'test value 2', 10 | nonQueryParam: 'test value 3' 11 | }); 12 | let qp = { 13 | qps: [ 14 | { 15 | prop: 'myParam1', 16 | defaultValue: 'test default value 1' 17 | }, 18 | { 19 | prop: 'myParam2' 20 | } 21 | ] 22 | }; 23 | return QueryParamsResetRoute.create({ 24 | controller, 25 | _qp: qp 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /tests/dummy/app/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | 12 | 13 | 14 | 15 | {{content-for "head-footer"}} 16 | 17 | 18 | {{content-for "body"}} 19 | 20 | 21 | 22 | 23 | {{content-for "body-footer"}} 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/acceptance/route-with-query-params-reset-test.js: -------------------------------------------------------------------------------- 1 | import { click, currentURL, visit } from '@ember/test-helpers'; 2 | import { module, test } from 'qunit'; 3 | import { setupApplicationTest } from 'ember-qunit'; 4 | 5 | module('Acceptance | route with query params reset', function(hooks) { 6 | setupApplicationTest(hooks); 7 | 8 | test('visiting /route-with-query-params-reset', async function(assert) { 9 | await visit('/route-with-query-params-reset'); 10 | 11 | assert.equal(currentURL(), '/route-with-query-params-reset'); 12 | 13 | await click('button'); 14 | 15 | assert.equal(currentURL(), '/route-with-query-params-reset?aParam=true'); 16 | 17 | await visit('/'); 18 | 19 | assert.equal(currentURL(), '/'); 20 | 21 | await click('#route-with-query-params-reset'); 22 | 23 | assert.equal(currentURL(), '/route-with-query-params-reset'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /tests/acceptance/route-without-query-params-reset-test.js: -------------------------------------------------------------------------------- 1 | import { click, currentURL, visit } from '@ember/test-helpers'; 2 | import { module, test } from 'qunit'; 3 | import { setupApplicationTest } from 'ember-qunit'; 4 | 5 | module('Acceptance | route without query params reset', function(hooks) { 6 | setupApplicationTest(hooks); 7 | 8 | test('visiting /route-without-query-params-reset', async function(assert) { 9 | await visit('/route-without-query-params-reset'); 10 | 11 | assert.equal(currentURL(), '/route-without-query-params-reset'); 12 | 13 | await click('button'); 14 | 15 | assert.equal(currentURL(), '/route-without-query-params-reset?aParam=true'); 16 | 17 | await visit('/'); 18 | 19 | assert.equal(currentURL(), '/'); 20 | 21 | await click('#route-without-query-params-reset'); 22 | 23 | assert.equal(currentURL(), '/route-without-query-params-reset?aParam=true'); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016-2017 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /addon/utils/reset-query-params.js: -------------------------------------------------------------------------------- 1 | import { get, set } from '@ember/object'; 2 | 3 | function getQueryParams(route) { 4 | return get(route, '_qp.qps'); 5 | } 6 | 7 | function shouldResetQueryParam(queryParamsToReset, qp) { 8 | return !queryParamsToReset || queryParamsToReset.indexOf(qp.prop) !== -1; 9 | } 10 | 11 | function resetQueryParam(controller, qp) { 12 | set(controller, qp.prop, qp.defaultValue); 13 | 14 | return qp.defaultValue; 15 | } 16 | 17 | export default function resetQueryParams(route, optionalArrayOfQueryParams) { 18 | let controller = get(route, 'controller'); 19 | let qps = getQueryParams(route); 20 | 21 | let queryParamsToReset = optionalArrayOfQueryParams; 22 | 23 | let defaultValues = {}; 24 | 25 | for (let i in qps) { 26 | if (!Object.hasOwnProperty.call(qps, i)) { 27 | continue; 28 | } 29 | 30 | let qp = qps[i]; 31 | if (!shouldResetQueryParam(queryParamsToReset, qp)) { 32 | continue; 33 | } 34 | 35 | let defaultValue = resetQueryParam(controller, qp); 36 | 37 | defaultValues[qp.prop] = defaultValue; 38 | } 39 | 40 | return defaultValues; 41 | } 42 | -------------------------------------------------------------------------------- /tests/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dummy Tests 7 | 8 | 9 | 10 | {{content-for "head"}} 11 | {{content-for "test-head"}} 12 | 13 | 14 | 15 | 16 | 17 | {{content-for "head-footer"}} 18 | {{content-for "test-head-footer"}} 19 | 20 | 21 | {{content-for "body"}} 22 | {{content-for "test-body"}} 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | {{content-for "body-footer"}} 31 | {{content-for "test-body-footer"}} 32 | 33 | 34 | -------------------------------------------------------------------------------- /tests/unit/mixins/query-params-reset-route-test.js: -------------------------------------------------------------------------------- 1 | import { module, test } from 'qunit'; 2 | import createRoute from '../../helpers/create-route'; 3 | 4 | let controller; 5 | let subject; 6 | 7 | module('Unit | Mixin | query params reset route', function(hooks) { 8 | hooks.beforeEach(function() { 9 | subject = createRoute(); 10 | controller = subject.get('controller'); 11 | }); 12 | 13 | test('it does nothing if not exiting', function(assert) { 14 | let isExiting = false; 15 | 16 | subject.resetController(controller, isExiting); 17 | 18 | assert.strictEqual(controller.get('myParam1'), 'test value 1'); 19 | assert.strictEqual(controller.get('myParam2'), 'test value 2'); 20 | assert.strictEqual(controller.get('nonQueryParam'), 'test value 3'); 21 | }); 22 | 23 | test('it resets params on exit', function(assert) { 24 | let isExiting = true; 25 | 26 | subject.resetController(controller, isExiting); 27 | 28 | assert.strictEqual(controller.get('myParam1'), 'test default value 1'); 29 | assert.strictEqual(controller.get('myParam2'), undefined); 30 | assert.strictEqual(controller.get('nonQueryParam'), 'test value 3'); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | parserOptions: { 4 | ecmaVersion: 2017, 5 | sourceType: 'module' 6 | }, 7 | plugins: [ 8 | 'ember' 9 | ], 10 | extends: [ 11 | 'eslint:recommended', 12 | 'plugin:ember/recommended' 13 | ], 14 | env: { 15 | browser: true 16 | }, 17 | rules: { 18 | }, 19 | overrides: [ 20 | // node files 21 | { 22 | files: [ 23 | '.eslintrc.js', 24 | '.template-lintrc.js', 25 | 'ember-cli-build.js', 26 | 'index.js', 27 | 'testem.js', 28 | 'blueprints/*/index.js', 29 | 'config/**/*.js', 30 | 'tests/dummy/config/**/*.js' 31 | ], 32 | excludedFiles: [ 33 | 'addon/**', 34 | 'addon-test-support/**', 35 | 'app/**', 36 | 'tests/dummy/app/**' 37 | ], 38 | parserOptions: { 39 | sourceType: 'script', 40 | ecmaVersion: 2015 41 | }, 42 | env: { 43 | browser: false, 44 | node: true 45 | }, 46 | plugins: ['node'], 47 | rules: Object.assign({}, require('eslint-plugin-node').configs.recommended.rules, { 48 | // add your custom rules and overrides for node files here 49 | }) 50 | } 51 | ] 52 | }; 53 | -------------------------------------------------------------------------------- /tests/unit/utils/reset-query-params-test.js: -------------------------------------------------------------------------------- 1 | import resetQueryParams from 'ember-query-params-reset/utils/reset-query-params'; 2 | import { module, test } from 'qunit'; 3 | import createRoute from '../../helpers/create-route'; 4 | 5 | let controller; 6 | let subject; 7 | 8 | module('Unit | Utility | reset query params', function(hooks) { 9 | hooks.beforeEach(function() { 10 | subject = createRoute(); 11 | controller = subject.get('controller'); 12 | }); 13 | 14 | test('it resets all params', function(assert) { 15 | let defaultValues = resetQueryParams(subject); 16 | 17 | assert.strictEqual(controller.get('myParam1'), 'test default value 1'); 18 | assert.strictEqual(controller.get('myParam2'), undefined); 19 | assert.strictEqual(controller.get('nonQueryParam'), 'test value 3'); 20 | assert.deepEqual(defaultValues, { 21 | myParam1: 'test default value 1', 22 | myParam2: undefined 23 | }); 24 | }); 25 | 26 | test('it resets some params', function(assert) { 27 | let defaultValues = resetQueryParams(subject, ['myParam1']); 28 | 29 | assert.strictEqual(controller.get('myParam1'), 'test default value 1'); 30 | assert.strictEqual(controller.get('myParam2'), 'test value 2'); 31 | assert.strictEqual(controller.get('nonQueryParam'), 'test value 3'); 32 | assert.deepEqual(defaultValues, { 33 | myParam1: 'test default value 1' 34 | }); 35 | }); 36 | }); 37 | -------------------------------------------------------------------------------- /tests/dummy/config/environment.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = function(environment) { 4 | let ENV = { 5 | modulePrefix: 'dummy', 6 | environment, 7 | rootURL: '/', 8 | locationType: 'auto', 9 | EmberENV: { 10 | FEATURES: { 11 | // Here you can enable experimental features on an ember canary build 12 | // e.g. 'with-controller': true 13 | }, 14 | EXTEND_PROTOTYPES: { 15 | // Prevent Ember Data from overriding Date.parse. 16 | Date: false 17 | } 18 | }, 19 | 20 | APP: { 21 | // Here you can pass flags/options to your application instance 22 | // when it is created 23 | } 24 | }; 25 | 26 | if (environment === 'development') { 27 | // ENV.APP.LOG_RESOLVER = true; 28 | // ENV.APP.LOG_ACTIVE_GENERATION = true; 29 | // ENV.APP.LOG_TRANSITIONS = true; 30 | // ENV.APP.LOG_TRANSITIONS_INTERNAL = true; 31 | // ENV.APP.LOG_VIEW_LOOKUPS = true; 32 | } 33 | 34 | if (environment === 'test') { 35 | // Testem prefers this... 36 | ENV.locationType = 'none'; 37 | 38 | // keep test console output quieter 39 | ENV.APP.LOG_ACTIVE_GENERATION = false; 40 | ENV.APP.LOG_VIEW_LOOKUPS = false; 41 | 42 | ENV.APP.rootElement = '#ember-testing'; 43 | ENV.APP.autoboot = false; 44 | } 45 | 46 | if (environment === 'production') { 47 | ENV.locationType = 'hash'; 48 | ENV.rootURL = '/ember-query-params-reset/'; 49 | } 50 | 51 | return ENV; 52 | }; 53 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: node_js 3 | node_js: 4 | # we recommend testing addons with the same minimum supported node version as Ember CLI 5 | # so that your addon works for all apps 6 | - "6" 7 | 8 | sudo: false 9 | dist: trusty 10 | 11 | addons: 12 | chrome: stable 13 | 14 | cache: 15 | directories: 16 | - $HOME/.npm 17 | 18 | env: 19 | global: 20 | # See https://git.io/vdao3 for details. 21 | - JOBS=1 22 | 23 | branches: 24 | only: 25 | - master 26 | # npm version tags 27 | - /^v\d+\.\d+\.\d+/ 28 | 29 | jobs: 30 | fail_fast: true 31 | allow_failures: 32 | - env: EMBER_TRY_SCENARIO=ember-canary 33 | 34 | include: 35 | # runs linting and tests with current locked deps 36 | 37 | - stage: "Tests" 38 | name: "Tests" 39 | script: 40 | - npm run lint:hbs 41 | - npm run lint:js 42 | - npm test 43 | 44 | # we recommend new addons test the current and previous LTS 45 | # as well as latest stable release (bonus points to beta/canary) 46 | - stage: "Additional Tests" 47 | env: EMBER_TRY_SCENARIO=ember-lts-2.16 48 | - env: EMBER_TRY_SCENARIO=ember-lts-2.18 49 | - env: EMBER_TRY_SCENARIO=ember-release 50 | - env: EMBER_TRY_SCENARIO=ember-beta 51 | - env: EMBER_TRY_SCENARIO=ember-canary 52 | - env: EMBER_TRY_SCENARIO=ember-default-with-jquery 53 | 54 | before_install: 55 | - npm config set spin false 56 | - npm install -g npm@5 57 | - npm --version 58 | 59 | script: 60 | - node_modules/.bin/ember try:one $EMBER_TRY_SCENARIO 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ember-query-params-reset", 3 | "version": "3.0.0", 4 | "description": "Automatically reset all query params when leaving a route", 5 | "keywords": [ 6 | "ember-addon" 7 | ], 8 | "license": "MIT", 9 | "author": "Kelly Selden", 10 | "directories": { 11 | "doc": "doc", 12 | "test": "tests" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/kellyselden/ember-query-params-reset.git" 17 | }, 18 | "scripts": { 19 | "build": "ember build", 20 | "lint:hbs": "ember-template-lint .", 21 | "lint:js": "eslint .", 22 | "start": "ember serve", 23 | "test": "ember test", 24 | "test:all": "ember try:each" 25 | }, 26 | "dependencies": { 27 | "ember-cli-babel": "^7.1.2" 28 | }, 29 | "devDependencies": { 30 | "@ember/optional-features": "^0.7.0", 31 | "broccoli-asset-rev": "^3.0.0", 32 | "ember-cli": "~3.6.0", 33 | "ember-cli-dependency-checker": "^3.0.0", 34 | "ember-cli-eslint": "^5.0.0", 35 | "ember-cli-github-pages": "0.2.1", 36 | "ember-cli-htmlbars": "^3.0.0", 37 | "ember-cli-inject-live-reload": "^2.0.0", 38 | "ember-cli-sri": "^2.1.1", 39 | "ember-cli-template-lint": "^1.0.0-beta.1", 40 | "ember-cli-uglify": "^2.1.0", 41 | "ember-disable-prototype-extensions": "^1.1.3", 42 | "ember-load-initializers": "^2.0.0", 43 | "ember-maybe-import-regenerator": "^0.1.6", 44 | "ember-qunit": "^4.0.0", 45 | "ember-resolver": "^5.0.1", 46 | "ember-source": "~3.6.0", 47 | "ember-source-channel-url": "^1.1.0", 48 | "ember-try": "^0.2.23", 49 | "eslint-plugin-ember": "^6.0.0", 50 | "eslint-plugin-node": "^8.0.0", 51 | "loader.js": "^4.7.0", 52 | "qunit-dom": "^0.8.0" 53 | }, 54 | "engines": { 55 | "node": "6.* || 8.* || >= 10.*" 56 | }, 57 | "ember-addon": { 58 | "configPath": "tests/dummy/config", 59 | "demoURL": "https://kellyselden.github.io/ember-query-params-reset" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ember-query-params-reset 2 | ============================================================================== 3 | 4 | [![Greenkeeper badge](https://badges.greenkeeper.io/kellyselden/ember-query-params-reset.svg)](https://greenkeeper.io/) 5 | [![npm version](https://badge.fury.io/js/ember-query-params-reset.svg)](https://badge.fury.io/js/ember-query-params-reset) 6 | [![Build Status](https://travis-ci.org/kellyselden/ember-query-params-reset.svg?branch=master)](https://travis-ci.org/kellyselden/ember-query-params-reset) 7 | [![Ember Version](https://img.shields.io/badge/ember-2.16%2B-brightgreen.svg)](https://www.emberjs.com/) 8 | 9 | Automatically reset all query params when leaving a route 10 | 11 | Demo 12 | ------------------------------------------------------------------------------ 13 | 14 | https://kellyselden.github.io/ember-query-params-reset 15 | 16 | 17 | Installation 18 | ------------------------------------------------------------------------------ 19 | 20 | ``` 21 | ember install ember-query-params-reset 22 | ``` 23 | 24 | 25 | Usage 26 | ------------------------------------------------------------------------------ 27 | 28 | ```js 29 | import Ember from 'ember'; 30 | import QueryParamsResetRouteMixin from 'ember-query-params-reset/mixins/query-params-reset-route'; 31 | 32 | export default Ember.Route.extend(QueryParamsResetRouteMixin, { 33 | // the rest of your logic 34 | }); 35 | ``` 36 | 37 | You can also use the util manually to reset query params at-will: 38 | 39 | ```js 40 | import resetQueryParams from 'ember-query-params-reset/utils/reset-query-params'; 41 | 42 | // ... 43 | 44 | resetQueryParams(myRoute, ['myQueryParam']); // reset some 45 | let defaultValues = resetQueryParams(myRoute); // reset all 46 | console.log(defaultValues); // { myQueryParam: 'default value', /* etc... */ } 47 | ``` 48 | 49 | 50 | License 51 | ------------------------------------------------------------------------------ 52 | 53 | This project is licensed under the [MIT License](LICENSE.md). 54 | -------------------------------------------------------------------------------- /config/ember-try.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const getChannelURL = require('ember-source-channel-url'); 4 | 5 | module.exports = function() { 6 | return Promise.all([ 7 | getChannelURL('release'), 8 | getChannelURL('beta'), 9 | getChannelURL('canary') 10 | ]).then((urls) => { 11 | return { 12 | scenarios: [ 13 | { 14 | name: 'ember-lts-2.16', 15 | env: { 16 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }) 17 | }, 18 | npm: { 19 | devDependencies: { 20 | '@ember/jquery': '^0.5.1', 21 | 'ember-source': '~2.16.0' 22 | } 23 | } 24 | }, 25 | { 26 | name: 'ember-lts-2.18', 27 | env: { 28 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 'jquery-integration': true }) 29 | }, 30 | npm: { 31 | devDependencies: { 32 | '@ember/jquery': '^0.5.1', 33 | 'ember-source': '~2.18.0' 34 | } 35 | } 36 | }, 37 | { 38 | name: 'ember-release', 39 | npm: { 40 | devDependencies: { 41 | 'ember-source': urls[0] 42 | } 43 | } 44 | }, 45 | { 46 | name: 'ember-beta', 47 | npm: { 48 | devDependencies: { 49 | 'ember-source': urls[1] 50 | } 51 | } 52 | }, 53 | { 54 | name: 'ember-canary', 55 | npm: { 56 | devDependencies: { 57 | 'ember-source': urls[2] 58 | } 59 | } 60 | }, 61 | { 62 | name: 'ember-default-with-jquery', 63 | env: { 64 | EMBER_OPTIONAL_FEATURES: JSON.stringify({ 65 | 'jquery-integration': true 66 | }) 67 | }, 68 | npm: { 69 | devDependencies: { 70 | '@ember/jquery': '^0.5.1' 71 | } 72 | } 73 | } 74 | ] 75 | }; 76 | }); 77 | }; 78 | --------------------------------------------------------------------------------