@uirouter/dsr
Advanced tools
Comparing version
/** | ||
* UI-Router Deep State Redirect: redirect to the most recently activated child state | ||
* @version v1.1.1 | ||
* @version v1.2.0 | ||
* @link https://ui-router.github.io | ||
@@ -11,3 +11,3 @@ * @license MIT License, http://www.opensource.org/licenses/MIT | ||
(global = global || self, factory(global['@uirouter/dsr'] = {}, global['@uirouter/core'])); | ||
}(this, function (exports, core) { 'use strict'; | ||
}(this, (function (exports, core) { 'use strict'; | ||
@@ -215,3 +215,3 @@ var __extends = (undefined && undefined.__extends) || (function () { | ||
var currentDSRS = _this.dataStore.get(_state); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, _this.getConfig(state).params, true); | ||
var updatedDSRS = currentDSRS.filter(predicate).concat(recordedDSR); | ||
@@ -269,3 +269,3 @@ _this.dataStore.set(_state, updatedDSRS); | ||
})); | ||
}))); | ||
//# sourceMappingURL=ui-router-dsr.js.map |
/** | ||
* UI-Router Deep State Redirect: redirect to the most recently activated child state | ||
* @version v1.1.1 | ||
* @version v1.2.0 | ||
* @link https://ui-router.github.io | ||
* @license MIT License, http://www.opensource.org/licenses/MIT | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@uirouter/core")):"function"==typeof define&&define.amd?define(["exports","@uirouter/core"],e):e((t=t||self)["@uirouter/dsr"]={},t["@uirouter/core"])}(this,function(t,a){"use strict";var o,e=(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=(r.prototype.getState=function(t){var e=this.router.stateService.get(t);return e&&e.$$state()},r.prototype.init=function(t){this.router=t},r.prototype.get=function(t){return this.getState(t).$dsr||[]},r.prototype.set=function(t,e){var r=this.getState(t);e?r.$dsr=e:delete r.$dsr},r);function r(){}var s=(n.prototype.getStore=function(){var t=this._storage.getItem(this.key);return JSON.parse(t||"{}")},n.prototype.setStore=function(e){if(e)try{this._storage.setItem(this.key,JSON.stringify(e))}catch(t){console.error("UI-Router Deep State Redirect: cannot store object in LocalStorage. Is there a circular reference?",e),console.error(t)}else this._storage.removeItem(this.key)},n.prototype.getStateName=function(t){var e=this.router.stateService.get(t);return e&&e.name},n.prototype.init=function(t){this.router=t},n.prototype.get=function(t){var e=this.getStateName(t);return this.getStore()[e]||[]},n.prototype.set=function(t,e){var r=this.getStateName(t),o=this.getStore();o[r]=e,this.setStore(o)},n);function n(t){this.key="uiRouterDeepStateRedirect",this._storage=localStorage,this._storage=t||localStorage}var u;e(p,u=s);function p(){return u.call(this,sessionStorage)||this}var f=(c.prototype.dispose=function(t){this.hookDeregFns.forEach(function(t){return t()})},c.prototype.reset=function(t,e){var r=this,o=this.$state;if(t)if(e){var i=this.dataStore.get(t),a=o.get(t).$$state();this.dataStore.set(t,i.filter(this.paramsEqual(a,e,void 0,!0)))}else this.dataStore.set(t,void 0);else o.get().forEach(function(t){return r.dataStore.set(t,void 0)})},c.prototype.getRedirect=function(t,e){return this.getDeepStateRedirect(t,e)},c.prototype.getDsrProp=function(t){return t.deepStateRedirect||t.dsr},c.prototype.getConfig=function(t){var e=this.$state,r=this.getDsrProp(t);if(void 0!==r){var o,i="string"==typeof r?e.target(r):void 0,a="function"==typeof r?r:void 0;if("object"==typeof r){a=r.fn,"object"==typeof r.default?i=e.target(r.default.state,r.default.params,r.default.options):"string"==typeof r.default&&(i=e.target(r.default));var s=r.params;!0===s?o=function(){return!0}:Array.isArray(s)&&(o=function(t){return-1!==s.indexOf(t.id)})}return{default:i,params:o,fn:a=a||function(t,e){return e}}}},c.prototype.paramsEqual=function(t,r,e,o){void 0===e&&(e=function(){return!0}),void 0===o&&(o=!1);var i=t.parameters({inherit:!0}).filter(e);return function(t){var e=a.Param.equals(i,t.triggerParams,r);return o?!e:e}},c.prototype.recordDeepState=function(n,t){var u=this,p=this.$state,f=!!this.getConfig(t).params,c=t.$$state();n.promise.then(function(){var t=n.to(),e=n.params(),r=p.target(t,e),o={triggerParams:e,targetStateName:r.name(),targetParams:r.params()};if(f){var i=u.dataStore.get(c),a=u.paramsEqual(t.$$state(),e,void 0,!0),s=i.filter(a).concat(o);u.dataStore.set(c,s)}else u.dataStore.set(c,[o])})},c.prototype.deepStateRedirect=function(t){var e=t.options();if(!(e.ignoreDsr||e.custom&&e.custom.ignoreDsr)){var r=this.getConfig(t.to()),o=this.getDeepStateRedirect(t.to(),t.params());if(!(o=r.fn(t,o))||o.state()!==t.to())return o}},c.prototype.getTargetState=function(t){return this.$state.target(t.targetStateName,t.targetParams)},c.prototype.getDeepStateRedirect=function(t,e){var r,o=this.$state,i=o.get(t),a=i&&i.$$state(),s=this.getConfig(i),n=this.dataStore.get(t);if(s.params){var u=this.paramsEqual(a,e,s.params,!1),p=n.find(u);r=p&&p}else r=n[0]&&n[0];var f=r?this.getTargetState(r):s.default;if(f){var c=Object.assign({},e,f.params());f=o.target(f.state(),c,f.options())}return f},c);function c(t,e){var r=this;this.name="deep-state-redirect",this.hookDeregFns=[],this.$transitions=t.transitionService,this.$state=t.stateService,this.dataStore=e&&e.dataStore||new i,this.dataStore.init(t),this.hookDeregFns.push(this.$transitions.onRetain({retained:function(t){return!!r.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onEnter({entering:function(t){return!!r.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onBefore({to:function(t){return!!r.getDsrProp(t.self)}},this.deepStateRedirect.bind(this)))}t.DSRPlugin=f,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@uirouter/core")):"function"==typeof define&&define.amd?define(["exports","@uirouter/core"],e):e((t=t||self)["@uirouter/dsr"]={},t["@uirouter/core"])}(this,function(t,a){"use strict";var o,e=(o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)},function(t,e){function r(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}),i=(r.prototype.getState=function(t){var e=this.router.stateService.get(t);return e&&e.$$state()},r.prototype.init=function(t){this.router=t},r.prototype.get=function(t){return this.getState(t).$dsr||[]},r.prototype.set=function(t,e){var r=this.getState(t);e?r.$dsr=e:delete r.$dsr},r);function r(){}var s=(n.prototype.getStore=function(){var t=this._storage.getItem(this.key);return JSON.parse(t||"{}")},n.prototype.setStore=function(e){if(e)try{this._storage.setItem(this.key,JSON.stringify(e))}catch(t){console.error("UI-Router Deep State Redirect: cannot store object in LocalStorage. Is there a circular reference?",e),console.error(t)}else this._storage.removeItem(this.key)},n.prototype.getStateName=function(t){var e=this.router.stateService.get(t);return e&&e.name},n.prototype.init=function(t){this.router=t},n.prototype.get=function(t){var e=this.getStateName(t);return this.getStore()[e]||[]},n.prototype.set=function(t,e){var r=this.getStateName(t),o=this.getStore();o[r]=e,this.setStore(o)},n);function n(t){this.key="uiRouterDeepStateRedirect",this._storage=localStorage,this._storage=t||localStorage}var u;e(p,u=s);function p(){return u.call(this,sessionStorage)||this}var f=(c.prototype.dispose=function(t){this.hookDeregFns.forEach(function(t){return t()})},c.prototype.reset=function(t,e){var r=this,o=this.$state;if(t)if(e){var i=this.dataStore.get(t),a=o.get(t).$$state();this.dataStore.set(t,i.filter(this.paramsEqual(a,e,void 0,!0)))}else this.dataStore.set(t,void 0);else o.get().forEach(function(t){return r.dataStore.set(t,void 0)})},c.prototype.getRedirect=function(t,e){return this.getDeepStateRedirect(t,e)},c.prototype.getDsrProp=function(t){return t.deepStateRedirect||t.dsr},c.prototype.getConfig=function(t){var e=this.$state,r=this.getDsrProp(t);if(void 0!==r){var o,i="string"==typeof r?e.target(r):void 0,a="function"==typeof r?r:void 0;if("object"==typeof r){a=r.fn,"object"==typeof r.default?i=e.target(r.default.state,r.default.params,r.default.options):"string"==typeof r.default&&(i=e.target(r.default));var s=r.params;!0===s?o=function(){return!0}:Array.isArray(s)&&(o=function(t){return-1!==s.indexOf(t.id)})}return{default:i,params:o,fn:a=a||function(t,e){return e}}}},c.prototype.paramsEqual=function(t,r,e,o){void 0===e&&(e=function(){return!0}),void 0===o&&(o=!1);var i=t.parameters({inherit:!0}).filter(e);return function(t){var e=a.Param.equals(i,t.triggerParams,r);return o?!e:e}},c.prototype.recordDeepState=function(n,u){var p=this,f=this.$state,c=!!this.getConfig(u).params,g=u.$$state();n.promise.then(function(){var t=n.to(),e=n.params(),r=f.target(t,e),o={triggerParams:e,targetStateName:r.name(),targetParams:r.params()};if(c){var i=p.dataStore.get(g),a=p.paramsEqual(t.$$state(),e,p.getConfig(u).params,!0),s=i.filter(a).concat(o);p.dataStore.set(g,s)}else p.dataStore.set(g,[o])})},c.prototype.deepStateRedirect=function(t){var e=t.options();if(!(e.ignoreDsr||e.custom&&e.custom.ignoreDsr)){var r=this.getConfig(t.to()),o=this.getDeepStateRedirect(t.to(),t.params());if(!(o=r.fn(t,o))||o.state()!==t.to())return o}},c.prototype.getTargetState=function(t){return this.$state.target(t.targetStateName,t.targetParams)},c.prototype.getDeepStateRedirect=function(t,e){var r,o=this.$state,i=o.get(t),a=i&&i.$$state(),s=this.getConfig(i),n=this.dataStore.get(t);if(s.params){var u=this.paramsEqual(a,e,s.params,!1),p=n.find(u);r=p&&p}else r=n[0]&&n[0];var f=r?this.getTargetState(r):s.default;if(f){var c=Object.assign({},e,f.params());f=o.target(f.state(),c,f.options())}return f},c);function c(t,e){var r=this;this.name="deep-state-redirect",this.hookDeregFns=[],this.$transitions=t.transitionService,this.$state=t.stateService,this.dataStore=e&&e.dataStore||new i,this.dataStore.init(t),this.hookDeregFns.push(this.$transitions.onRetain({retained:function(t){return!!r.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onEnter({entering:function(t){return!!r.getDsrProp(t.self)}},this.recordDeepState.bind(this))),this.hookDeregFns.push(this.$transitions.onBefore({to:function(t){return!!r.getDsrProp(t.self)}},this.deepStateRedirect.bind(this)))}t.DSRPlugin=f,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=ui-router-dsr.min.js.map |
@@ -0,1 +1,9 @@ | ||
# 1.2.0 (2019-12-26) | ||
[Compare `@uirouter/dsr` versions 1.1.1 and 1.2.0](https://github.com/ui-router/dsr/compare/1.1.1...1.2.0) | ||
### Bug Fixes | ||
- **params:** When performing DSR with param criteria, only consider the parameters listed in the dsr configuration block ([d073218](https://github.com/ui-router/dsr/commit/d073218)) | ||
## 1.1.1 (2019-10-08) | ||
@@ -2,0 +10,0 @@ |
@@ -115,3 +115,3 @@ import { Param, } from '@uirouter/core'; | ||
var currentDSRS = _this.dataStore.get(_state); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, _this.getConfig(state).params, true); | ||
var updatedDSRS = currentDSRS.filter(predicate).concat(recordedDSR); | ||
@@ -118,0 +118,0 @@ _this.dataStore.set(_state, updatedDSRS); |
@@ -117,3 +117,3 @@ "use strict"; | ||
var currentDSRS = _this.dataStore.get(_state); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, undefined, true); | ||
var predicate = _this.paramsEqual(transTo.$$state(), triggerParams, _this.getConfig(state).params, true); | ||
var updatedDSRS = currentDSRS.filter(predicate).concat(recordedDSR); | ||
@@ -120,0 +120,0 @@ _this.dataStore.set(_state, updatedDSRS); |
{ | ||
"name": "@uirouter/dsr", | ||
"description": "UI-Router Deep State Redirect: redirect to the most recently activated child state", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"scripts": { | ||
@@ -53,4 +53,4 @@ "clean": "shx rm -rf lib lib-esm _bundles", | ||
"@types/lodash": "^4.14.119", | ||
"@uirouter/core": "^5.0.22", | ||
"@uirouter/publish-scripts": "^2.3.33", | ||
"@uirouter/core": "^6.0.1", | ||
"@uirouter/publish-scripts": "^2.3.42", | ||
"husky": "^3.0.5", | ||
@@ -67,3 +67,3 @@ "jasmine-core": "^3.3.0", | ||
"prettier": "^1.15.3", | ||
"pretty-quick": "^1.8.1", | ||
"pretty-quick": "^2.0.1", | ||
"rollup": "^1.1.0", | ||
@@ -74,3 +74,3 @@ "rollup-plugin-node-resolve": "^5.2.0", | ||
"ts-loader": "^6.0.4", | ||
"tslint": "5.19.0", | ||
"tslint": "5.20.1", | ||
"tslint-eslint-rules": "^5.4.0", | ||
@@ -77,0 +77,0 @@ "typescript": "^3.2.2", |
# Deep State Redirect | ||
[](https://greenkeeper.io/) | ||
### DSR for UI-Router 1.0 [](https://github.com/ui-router/dsr/actions?query=workflow%3A%22CI%3A+Deep+State+Redirect+for+UIRouter%22) | ||
### DSR for UI-Router 1.0 [](https://travis-ci.org/christopherthielen/deep-state-redirect) | ||
With Deep State Redirect, a parent state remembers whatever child state was last activated. | ||
@@ -8,0 +6,0 @@ When the user directly reactivates the parent state, they are redirected to the nested state (which was previously activated). |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
410255
117.53%91
1.11%54
-3.57%