mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Cleanup hash routing
This commit is contained in:
parent
939eb0fd78
commit
3757324e32
7 changed files with 8 additions and 52 deletions
|
|
@ -40,19 +40,12 @@ export class AbstractScreen {
|
|||
* @returns {void}
|
||||
*/
|
||||
__start() {
|
||||
let route = null,
|
||||
fMatcher = null;
|
||||
const routes = this.routes();
|
||||
|
||||
if (Array.isNotEmpty(routes)) {
|
||||
fMatcher = (this.onRoute || (()=>{})).bind(this);
|
||||
route = new Crossroads();
|
||||
let route = new Crossroads(),
|
||||
fMatcher = (this.onRoute || (()=>{})).bind(this);
|
||||
|
||||
routes.forEach((item) => {
|
||||
if (item && route) {
|
||||
route.addRoute(item[0], fMatcher).rules = item[1];
|
||||
}
|
||||
});
|
||||
routes.forEach(item => item && route && (route.addRoute(item[0], fMatcher).rules = item[1]));
|
||||
|
||||
this.oCross = route;
|
||||
}
|
||||
|
|
|
|||
12
vendors/routes/crossroads.js
vendored
12
vendors/routes/crossroads.js
vendored
|
|
@ -61,14 +61,6 @@
|
|||
route._destroy();
|
||||
}
|
||||
|
||||
removeAllRoutes() {
|
||||
var n = this.getNumRoutes();
|
||||
while (n--) {
|
||||
this._routes[n]._destroy();
|
||||
}
|
||||
this._routes.length = 0;
|
||||
}
|
||||
|
||||
parse(request) {
|
||||
request = request || '';
|
||||
|
||||
|
|
@ -91,10 +83,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
getNumRoutes() {
|
||||
return this._routes.length;
|
||||
}
|
||||
|
||||
_getMatchedRoutes(request) {
|
||||
var res = [],
|
||||
routes = this._routes,
|
||||
|
|
|
|||
2
vendors/routes/crossroads.min.js
vendored
2
vendors/routes/crossroads.min.js
vendored
|
|
@ -4,4 +4,4 @@
|
|||
Author: Miller Medeiros
|
||||
Version: 0.7.1 - Build: 93 (2012/02/02 09:29 AM)
|
||||
*/
|
||||
(e=>{function t(e){return null===e||"null"===e?null:"true"===e||"false"!==e&&(void 0===e||"undefined"===e?void 0:""===e||isNaN(e)?e:parseFloat(e))}class s{constructor(t,s,r,a){this.greedy=!1,this.rules=void 0;var i=t instanceof RegExp;this._router=a,this._pattern=t,this._paramsIds=i?null:c.getParamIds(this._pattern),this._optionalParamsIds=i?null:c.getOptionalParamsIds(this._pattern),this._matchRegexp=i?t:c.compilePattern(t),this.matched=new e.signals.Signal,s&&this.matched.add(s),this._priority=r||0}match(e){return this._matchRegexp.test(e)&&this._validateParams(e)}_validateParams(e){var t,s=this.rules,r=this._getParamsObject(e);for(t in s)if("normalize_"!==t&&s.hasOwnProperty(t)&&!this._isValidParam(e,t,r))return!1;return!0}_isValidParam(e,t,s){var r=this.rules[t],a=s[t],i=!1;return null==a&&this._optionalParamsIds&&-1!==this._optionalParamsIds.indexOf(t)?i=!0:r instanceof RegExp?i=r.test(a):Array.isArray(r)?i=-1!==r.indexOf(a):"function"==typeof r&&(i=r(a,e,s)),i}_getParamsObject(e){for(var s=this._router.shouldTypecast,r=c.getParamValues(e,this._matchRegexp,s),a={},i=r.length;i--;)a[i]=r[i],this._paramsIds&&(a[this._paramsIds[i]]=r[i]);return a.request_=s?t(e):e,a.vals_=r,a}_getParamsArray(e){var t=this.rules?this.rules.normalize_:null;return t&&"function"==typeof t?t(e,this._getParamsObject(e)):c.getParamValues(e,this._matchRegexp,this._router.shouldTypecast)}dispose(){this._router.removeRoute(this)}_destroy(){this.matched.dispose(),this.matched=this._pattern=this._matchRegexp=null}}const r=/[\\.+*?^$[\](){}\/'#]/g,a=/\/$/g,i=/([:}]|\w(?=\/))\/?(:)/g,_=/([:}])\/?(\{)/g,h=/\{([^}]+)\}/g,o=/:([^:]+):/g,l=/(?:\{|:)([^}:]+)(?:\}|:)/g,n=new RegExp("__CR_RP__","g"),u=new RegExp("__CR_OP__","g"),p=new RegExp("__CR_OS__","g"),g=new RegExp("__CR_RS__","g"),d=(e,t)=>{for(var s,r=[];s=e.exec(t);)r.push(s[1]);return r},c={getParamIds:e=>d(l,e),getOptionalParamsIds:e=>d(o,e),getParamValues:(e,s,r)=>{var a=s.exec(e);return a&&(a.shift(),r&&(a=a.map(e=>t(e)))),a},compilePattern:e=>((e=e||"")&&(e=(e=>e.replace(p,"\\/?").replace(g,"\\/").replace(u,"([^\\/]+)?/?").replace(n,"([^\\/]+)"))((e=>e.replace(i,"$1__CR_OS__$2").replace(_,"$1__CR_RS__$2").replace(o,"__CR_OP__").replace(h,"__CR_RP__"))(e.replace(a,"")).replace(r,"\\$&"))),new RegExp("^"+e+"/?$"))};e.Crossroads=class{constructor(){this._routes=[],this.bypassed=new signals.Signal,this.routed=new e.signals.Signal,this.shouldTypecast=!1}addRoute(e,t,r){var a=new s(e,t,r,this),i=this._routes,_=i.length;do{--_}while(i[_]&&a._priority<=i[_]._priority);return i.splice(_+1,0,a),a}removeRoute(e){var t=this._routes.indexOf(e);-1!==t&&this._routes.splice(t,1),e._destroy()}removeAllRoutes(){for(var e=this.getNumRoutes();e--;)this._routes[e]._destroy();this._routes.length=0}parse(e){e=e||"";var t,s=this._getMatchedRoutes(e),r=0,a=s.length;if(a)for(;r<a;)(t=s[r]).route.matched.dispatch.apply(t.route.matched,t.params),t.isFirst=!r,this.routed.dispatch(e,t),r+=1;else this.bypassed.dispatch(e)}getNumRoutes(){return this._routes.length}_getMatchedRoutes(e){for(var t,s=[],r=this._routes,a=r.length;t=r[--a];)s.length&&!t.greedy||!t.match(e)||s.push({route:t,params:t._getParamsArray(e)});return s}}})(this);
|
||||
(e=>{function t(e){return null===e||"null"===e?null:"true"===e||"false"!==e&&(void 0===e||"undefined"===e?void 0:""===e||isNaN(e)?e:parseFloat(e))}class s{constructor(t,s,a,r){this.greedy=!1,this.rules=void 0;var i=t instanceof RegExp;this._router=r,this._pattern=t,this._paramsIds=i?null:g.getParamIds(this._pattern),this._optionalParamsIds=i?null:g.getOptionalParamsIds(this._pattern),this._matchRegexp=i?t:g.compilePattern(t),this.matched=new e.signals.Signal,s&&this.matched.add(s),this._priority=a||0}match(e){return this._matchRegexp.test(e)&&this._validateParams(e)}_validateParams(e){var t,s=this.rules,a=this._getParamsObject(e);for(t in s)if("normalize_"!==t&&s.hasOwnProperty(t)&&!this._isValidParam(e,t,a))return!1;return!0}_isValidParam(e,t,s){var a=this.rules[t],r=s[t],i=!1;return null==r&&this._optionalParamsIds&&-1!==this._optionalParamsIds.indexOf(t)?i=!0:a instanceof RegExp?i=a.test(r):Array.isArray(a)?i=-1!==a.indexOf(r):"function"==typeof a&&(i=a(r,e,s)),i}_getParamsObject(e){for(var s=this._router.shouldTypecast,a=g.getParamValues(e,this._matchRegexp,s),r={},i=a.length;i--;)r[i]=a[i],this._paramsIds&&(r[this._paramsIds[i]]=a[i]);return r.request_=s?t(e):e,r.vals_=a,r}_getParamsArray(e){var t=this.rules?this.rules.normalize_:null;return t&&"function"==typeof t?t(e,this._getParamsObject(e)):g.getParamValues(e,this._matchRegexp,this._router.shouldTypecast)}dispose(){this._router.removeRoute(this)}_destroy(){this.matched.dispose(),this.matched=this._pattern=this._matchRegexp=null}}const a=/[\\.+*?^$[\](){}\/'#]/g,r=/\/$/g,i=/([:}]|\w(?=\/))\/?(:)/g,_=/([:}])\/?(\{)/g,h=/\{([^}]+)\}/g,n=/:([^:]+):/g,l=/(?:\{|:)([^}:]+)(?:\}|:)/g,o=new RegExp("__CR_RP__","g"),p=new RegExp("__CR_OP__","g"),u=new RegExp("__CR_OS__","g"),c=new RegExp("__CR_RS__","g"),d=(e,t)=>{for(var s,a=[];s=e.exec(t);)a.push(s[1]);return a},g={getParamIds:e=>d(l,e),getOptionalParamsIds:e=>d(n,e),getParamValues:(e,s,a)=>{var r=s.exec(e);return r&&(r.shift(),a&&(r=r.map(e=>t(e)))),r},compilePattern:e=>((e=e||"")&&(e=(e=>e.replace(u,"\\/?").replace(c,"\\/").replace(p,"([^\\/]+)?/?").replace(o,"([^\\/]+)"))((e=>e.replace(i,"$1__CR_OS__$2").replace(_,"$1__CR_RS__$2").replace(n,"__CR_OP__").replace(h,"__CR_RP__"))(e.replace(r,"")).replace(a,"\\$&"))),new RegExp("^"+e+"/?$"))};e.Crossroads=class{constructor(){this._routes=[],this.bypassed=new signals.Signal,this.routed=new e.signals.Signal,this.shouldTypecast=!1}addRoute(e,t,a){var r=new s(e,t,a,this),i=this._routes,_=i.length;do{--_}while(i[_]&&r._priority<=i[_]._priority);return i.splice(_+1,0,r),r}removeRoute(e){var t=this._routes.indexOf(e);-1!==t&&this._routes.splice(t,1),e._destroy()}parse(e){e=e||"";var t,s=this._getMatchedRoutes(e),a=0,r=s.length;if(r)for(;a<r;)(t=s[a]).route.matched.dispatch.apply(t.route.matched,t.params),t.isFirst=!a,this.routed.dispatch(e,t),a+=1;else this.bypassed.dispatch(e)}_getMatchedRoutes(e){for(var t,s=[],a=this._routes,r=a.length;t=a[--r];)s.length&&!t.greedy||!t.match(e)||s.push({route:t,params:t._getParamsArray(e)});return s}}})(this);
|
||||
|
|
|
|||
6
vendors/routes/hasher.js
vendored
6
vendors/routes/hasher.js
vendored
|
|
@ -28,11 +28,7 @@
|
|||
// Private Methods
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
const _trimHash = hash => {
|
||||
if(! hash) return '';
|
||||
var regexp = new RegExp('^\\/|\\$', 'g');
|
||||
return hash.replace(regexp, '');
|
||||
},
|
||||
const _trimHash = hash => hash ? hash.replace(new RegExp('^\\/|\\$', 'g'), '') : '',
|
||||
_getWindowHash = () => {
|
||||
//parsed full URL instead of getting window.location.hash because Firefox decode hash value (and all the other browsers don't)
|
||||
//also because of IE8 bug with hash query in local file [issue #6]
|
||||
|
|
|
|||
2
vendors/routes/hasher.min.js
vendored
2
vendors/routes/hasher.min.js
vendored
|
|
@ -4,4 +4,4 @@
|
|||
* @version 1.1.2 (2012/10/31 03:19 PM)
|
||||
* Released under the MIT License
|
||||
*/
|
||||
(e=>{var i,a,n=signals.Signal,s=/#(.*)$/,t=/^#/;const r=e=>{if(!e)return"";var i=new RegExp("^\\/|\\$","g");return e.replace(i,"")},h=()=>{var i=s.exec(e.location.href);return i&&i[1]?decodeURIComponent(i[1]):""},o=e=>{if(i!==e){var a=i;i=e,l.changed.dispatch(r(e),r(a))}},c=()=>{var e=h();e!==i&&o(e)},d=e=>(e=e.join("/"))?"/"+e.replace(t,""):e,l={changed:new n,initialized:new n,init:()=>{a||(i=h(),e.addEventListener("hashchange",c),a=!0,l.initialized.dispatch(r(i)))},stop:()=>{a&&(e.removeEventListener("hashchange",c),a=!1)},setHash:(...a)=>{(a=d(a))!==i&&(o(a),a===i&&(e.location.hash="#"+encodeURI(a)))},replaceHash:(...a)=>{(a=d(a))!==i&&(o(a),a===i&&e.location.replace("#"+encodeURI(a)))},dispose:()=>{l.stop(),l.initialized.dispose(),l.changed.dispose(),e.hasher=null}};l.initialized.memorize=!0,e.hasher=l})(this);
|
||||
(e=>{var i,a,n=signals.Signal,s=/#(.*)$/,h=/^#/;const t=e=>e?e.replace(new RegExp("^\\/|\\$","g"),""):"",o=()=>{var i=s.exec(e.location.href);return i&&i[1]?decodeURIComponent(i[1]):""},c=e=>{if(i!==e){var a=i;i=e,l.changed.dispatch(t(e),t(a))}},d=()=>{var e=o();e!==i&&c(e)},r=e=>(e=e.join("/"))?"/"+e.replace(h,""):e,l={changed:new n,initialized:new n,init:()=>{a||(i=o(),e.addEventListener("hashchange",d),a=!0,l.initialized.dispatch(t(i)))},stop:()=>{a&&(e.removeEventListener("hashchange",d),a=!1)},setHash:(...a)=>{(a=r(a))!==i&&(c(a),a===i&&(e.location.hash="#"+encodeURI(a)))},replaceHash:(...a)=>{(a=r(a))!==i&&(c(a),a===i&&e.location.replace("#"+encodeURI(a)))},dispose:()=>{l.stop(),l.initialized.dispose(),l.changed.dispose(),e.hasher=null}};l.initialized.memorize=!0,e.hasher=l})(this);
|
||||
|
|
|
|||
23
vendors/routes/signals.js
vendored
23
vendors/routes/signals.js
vendored
|
|
@ -101,14 +101,7 @@
|
|||
* @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
|
||||
*/
|
||||
detach () {
|
||||
return this.isBound()? this._signal.remove(this._listener, this.context) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Boolean} `true` if binding is still bound to the signal and have a listener.
|
||||
*/
|
||||
isBound () {
|
||||
return (!!this._signal && !!this._listener);
|
||||
return (this._signal && this._listener) ? this._signal.remove(this._listener, this.context) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -118,20 +111,6 @@
|
|||
return this._isOnce;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Function} Handler function bound to the signal.
|
||||
*/
|
||||
getListener () {
|
||||
return this._listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Signal} Signal that listener is currently bound to.
|
||||
*/
|
||||
getSignal () {
|
||||
return this._signal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete instance properties
|
||||
* @private
|
||||
|
|
|
|||
2
vendors/routes/signals.min.js
vendored
2
vendors/routes/signals.min.js
vendored
|
|
@ -4,4 +4,4 @@
|
|||
Author: Miller Medeiros
|
||||
Version: 1.0.0 - Build: 268 (2012/11/29 05:48 PM)
|
||||
*/
|
||||
(i=>{class t{constructor(i,t,e,s,n){this.active=!0,this.params=null,this._listener=t,this._isOnce=e,this.context=s,this._signal=i,this._priority=n||0}execute(i){var t,e;return this.active&&this._listener&&(e=this.params?this.params.concat(i):i,t=this._listener.apply(this.context,e),this._isOnce&&this.detach()),t}detach(){return this.isBound()?this._signal.remove(this._listener,this.context):null}isBound(){return!!this._signal&&!!this._listener}isOnce(){return this._isOnce}getListener(){return this._listener}getSignal(){return this._signal}_destroy(){delete this._signal,delete this._listener,delete this.context}}function e(i,t){if("function"!=typeof i)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",t))}class s{constructor(){this.memorize=!1,this.active=!0,this._bindings=[],this._prevParams=null;var i=this;this.dispatch=((...t)=>s.prototype.dispatch.apply(i,t))}_indexOfListener(i,t){for(var e,s=this._bindings.length;s--;)if((e=this._bindings[s])._listener===i&&e.context===t)return s;return-1}add(i,s,n){e(i,"add");var r,h=this._indexOfListener(i,s);if(-1!==h){if(!1!==(r=this._bindings[h]).isOnce())throw new Error("You cannot addOnce() then add() the same listener without removing the relationship first.")}else{r=new t(this,i,!1,s,n);var a=this._bindings.length;do{--a}while(this._bindings[a]&&r._priority<=this._bindings[a]._priority);this._bindings.splice(a+1,0,r)}return this.memorize&&this._prevParams&&r.execute(this._prevParams),r}remove(i,t){e(i,"remove");var s=this._indexOfListener(i,t);return-1!==s&&(this._bindings[s]._destroy(),this._bindings.splice(s,1)),i}removeAll(){for(var i=this._bindings.length;i--;)this._bindings[i]._destroy();this._bindings.length=0}dispatch(...i){if(this.active){var t,e=this._bindings.length;if(this.memorize&&(this._prevParams=i),e){t=this._bindings.slice();do{e--}while(t[e]&&!1!==t[e].execute(i))}}}dispose(){this.removeAll(),delete this._bindings,delete this._prevParams}}var n=s;n.Signal=s,i.signals=n})(this);
|
||||
(i=>{class t{constructor(i,t,e,s,n){this.active=!0,this.params=null,this._listener=t,this._isOnce=e,this.context=s,this._signal=i,this._priority=n||0}execute(i){var t,e;return this.active&&this._listener&&(e=this.params?this.params.concat(i):i,t=this._listener.apply(this.context,e),this._isOnce&&this.detach()),t}detach(){return this._signal&&this._listener?this._signal.remove(this._listener,this.context):null}isOnce(){return this._isOnce}_destroy(){delete this._signal,delete this._listener,delete this.context}}function e(i,t){if("function"!=typeof i)throw new Error("listener is a required param of {fn}() and should be a Function.".replace("{fn}",t))}class s{constructor(){this.memorize=!1,this.active=!0,this._bindings=[],this._prevParams=null;var i=this;this.dispatch=((...t)=>s.prototype.dispatch.apply(i,t))}_indexOfListener(i,t){for(var e,s=this._bindings.length;s--;)if((e=this._bindings[s])._listener===i&&e.context===t)return s;return-1}add(i,s,n){e(i,"add");var r,h=this._indexOfListener(i,s);if(-1!==h){if(!1!==(r=this._bindings[h]).isOnce())throw new Error("You cannot addOnce() then add() the same listener without removing the relationship first.")}else{r=new t(this,i,!1,s,n);var a=this._bindings.length;do{--a}while(this._bindings[a]&&r._priority<=this._bindings[a]._priority);this._bindings.splice(a+1,0,r)}return this.memorize&&this._prevParams&&r.execute(this._prevParams),r}remove(i,t){e(i,"remove");var s=this._indexOfListener(i,t);return-1!==s&&(this._bindings[s]._destroy(),this._bindings.splice(s,1)),i}removeAll(){for(var i=this._bindings.length;i--;)this._bindings[i]._destroy();this._bindings.length=0}dispatch(...i){if(this.active){var t,e=this._bindings.length;if(this.memorize&&(this._prevParams=i),e){t=this._bindings.slice();do{e--}while(t[e]&&!1!==t[e].execute(i))}}}dispose(){this.removeAll(),delete this._bindings,delete this._prevParams}}var n=s;n.Signal=s,i.signals=n})(this);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue