@curi/core
Advanced tools
Comparing version 1.0.0-beta.24 to 1.0.0-beta.25
@@ -0,1 +1,5 @@ | ||
## 1.0.0-beta.25 | ||
* Add `initial` property to response handler options (default is `true`). When `false`, the response handler will not be called until a new response is emitted. | ||
## 1.0.0-beta.24 | ||
@@ -2,0 +6,0 @@ |
@@ -324,5 +324,5 @@ 'use strict'; | ||
} | ||
var _a = (options || {}).once, once = _a === void 0 ? false : _a; | ||
var _a = options || {}, _b = _a.once, once = _b === void 0 ? false : _b, _c = _a.initial, initial = _c === void 0 ? true : _c; | ||
if (once) { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -335,3 +335,3 @@ } | ||
else { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -338,0 +338,0 @@ } |
@@ -320,5 +320,5 @@ import PathToRegexp from 'path-to-regexp'; | ||
} | ||
var _a = (options || {}).once, once = _a === void 0 ? false : _a; | ||
var _a = options || {}, _b = _a.once, once = _b === void 0 ? false : _b, _c = _a.initial, initial = _c === void 0 ? true : _c; | ||
if (once) { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -331,3 +331,3 @@ } | ||
else { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -334,0 +334,0 @@ } |
@@ -698,5 +698,5 @@ var Curi = (function () { | ||
} | ||
var _a = (options || {}).once, once = _a === void 0 ? false : _a; | ||
var _a = options || {}, _b = _a.once, once = _b === void 0 ? false : _b, _c = _a.initial, initial = _c === void 0 ? true : _c; | ||
if (once) { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -709,3 +709,3 @@ } | ||
else { | ||
if (mostRecent.response) { | ||
if (mostRecent.response && initial) { | ||
fn.call(null, mostRecent.response, mostRecent.navigation, curi); | ||
@@ -712,0 +712,0 @@ } |
@@ -1,1 +0,1 @@ | ||
var Curi=function(){"use strict";function e(n,r,t){n.forEach(function(n){var a=r.register(n.public,t);e(n.children,r,a)})}function n(e,n){for(var r,o=[],i=0,u=0,c="",s=n&&n.delimiter||k,l=n&&n.delimiters||R,p=!1;null!==(r=$.exec(e));){var f=r[0],h=r[1],v=r.index;if(c+=e.slice(u,v),u=v+f.length,h)c+=h[1],p=!0;else{var d="",m=e[u],g=r[2],y=r[3],x=r[4],E=r[5];if(!p&&c.length){var b=c.length-1;l.indexOf(c[b])>-1&&(d=c[b],c=c.slice(0,b))}c&&(o.push(c),c="",p=!1);var w=""!==d&&void 0!==m&&m!==d,T="+"===E||"*"===E,A="?"===E||"*"===E,j=d||s,O=y||x;o.push({name:g||i++,prefix:d,delimiter:j,optional:A,repeat:T,partial:w,pattern:O?a(O):"[^"+t(j)+"]+?"})}}return(c||u<e.length)&&o.push(c+e.substr(u)),o}function r(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,t){for(var a="",o=t&&t.encode||encodeURIComponent,i=0;i<e.length;i++){var u=e[i];if("string"!=typeof u){var c,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var l=0;l<s.length;l++){if(c=o(s[l]),!n[i].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');a+=(0===l?u.prefix:u.delimiter)+c}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(a+=u.prefix)}else{if(c=o(String(s)),!n[i].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');a+=u.prefix+c}}else a+=u}return a}}function t(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function a(e){return e.replace(/([=!:$/()])/g,"\\$1")}function o(e){return e&&e.sensitive?"":"i"}function i(e,n){if(!n)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var t=0;t<r.length;t++)n.push({name:t,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function u(e,n,r){for(var t=[],a=0;a<e.length;a++)t.push(l(e[a],n,r).source);return new RegExp("(?:"+t.join("|")+")",o(r))}function c(e,r,t){return s(n(e,t),r,t)}function s(e,n,r){for(var a=(r=r||{}).strict,i=!1!==r.end,u=t(r.delimiter||k),c=r.delimiters||R,s=[].concat(r.endsWith||[]).map(t).concat("$").join("|"),l="",p=!1,f=0;f<e.length;f++){var h=e[f];if("string"==typeof h)l+=t(h),p=f===e.length-1&&c.indexOf(h[h.length-1])>-1;else{var v=t(h.prefix),d=h.repeat?"(?:"+h.pattern+")(?:"+v+"(?:"+h.pattern+"))*":h.pattern;n&&n.push(h),h.optional?h.partial?l+=v+"("+d+")?":l+="(?:"+v+"("+d+"))?":l+=v+"("+d+")"}}return i?(a||(l+="(?:"+u+")?"),l+="$"===s?"$":"(?="+s+")"):(a||(l+="(?:"+u+"(?="+s+"))?"),p||(l+="(?="+u+"|"+s+")")),new RegExp("^"+l,o(r))}function l(e,n,r){return e instanceof RegExp?i(e,n):Array.isArray(e)?u(e,n,r):c(e,n,r)}function p(e){var n={},r={};return{name:"pathname",register:function(e,r){var t=e.name,a=e.path;void 0!==n[t]&&console.warn('A pathname with the name "'+t+'" already exists. Each route shouldhave a unique name. By registering a pathname with a name that already exists, you are overwriting the existing pathname. This may break your application.');var o;return r&&n[r]&&(o=n[r]),n[t]=o?B(o,a):a,t},get:function(t,a){if(null!=n[t]){var o=r[t]?r[t]:r[t]=b.compile(n[t]);return j(o(a,e))}console.error("Could not generate pathname for "+t+" because it is not registered.")},reset:function(){n={},r={}}}}function f(e,n,r,t){var a=O(n),o=e.match,i=o.re,u=o.keys,c=o.mustBeExact,s=e.children,l=i.exec(a);if(!l)return!1;var p=l[0],h=l.slice(1),v={};u.forEach(function(e,n){v[e.name]=h[n]});var d=null!=t?B(t,p):j(p);if(r.push({route:e,params:v}),!s||!s.length)return!0;var m=a.slice(p.length),g=!!m.length,y=s.some(function(e){return f(e,m,r,d)});return!(c&&g&&!y)||(r.pop(),!1)}function h(e,n){if(!n)return e;var r={};for(var t in e){var a=e[t],o=n[t];if(o)try{a=o(a)}catch(n){console.error(n),a=e[t]}r[t]=a}return r}function v(e,n){return{params:n.params,location:n.location,name:e.public.name}}function d(e,n){var r,t=[],a=[],o={};if(n.some(function(n){return f(n,e.pathname,t)}),t.length){var i=t.pop();t.forEach(function(e){a.push(e.route.public.name),Object.assign(o,h(e.params,e.route.paramParsers))}),r=i.route,Object.assign(o,h(i.params,r.paramParsers))}return m(r,{location:e,params:o,partials:a,status:null!=r?200:404,body:void 0,data:void 0,title:""})}function m(e,n){if(!e)return Promise.resolve({route:e,props:n});var r=e.public.match;return Promise.all([r.initial?r.initial():void 0,r.every?r.every(v(e,n)):void 0]).then(function(r){var t=r[0],a=r[1];return{route:e,props:n,error:null,resolved:{initial:t,every:a}}},function(r){return{route:e,props:n,error:r,resolved:null}})}function g(e){return{redirect:function(n,r){void 0===r&&(r=301),e.status=r,e.redirectTo=n},error:function(n){e.error=n},status:function(n){e.status=n},data:function(n){e.data=n},body:function(n){e.body=n},title:function(n){e.title=n}}}function y(e,n){return Object.assign({key:n.location.key,name:e?e.public.name:void 0},n)}function x(e,n){var r=e.error,t=e.resolved,a=e.route,o=e.props;return a&&a.public.match.response&&a.public.match.response({error:r,resolved:t,route:v(a,o),set:g(o),addons:n}),y(a,o)}function E(e){var n=null,r=!1;return function(){return r?n:(n=e(),r=!0,n)}}var b=l,w=n,T=r,A=s,k="/",R="./",$=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");b.parse=w,b.compile=function(e,t){return r(n(e,t))},b.tokensToFunction=T,b.tokensToRegExp=A;var j=function(e){return"/"===e.charAt(0)?e:"/"+e},O=function(e){return"/"===e.charAt(0)?e.slice(1):e},P=function(e){return"/"===e.charAt(e.length-1)?e:e+"/"},B=function(e,n){return P(e)+n},C=function(e){var n=e.name,r=e.path,t=e.pathOptions,a=void 0===t?{}:t,o=e.children,i=void 0===o?[]:o,u=e.match,c=void 0===u?{}:u,s=e.extra,l=e.params,p=null==a.end||a.end,f=[];i.length&&(a.end=!1,f=i.map(C));var h=[],v=b(r,h,a);return{public:{name:n,path:r,keys:h.map(function(e){return e.name}),match:{initial:c.initial&&E(c.initial),every:c.every,response:c.response},extra:s},match:{re:v,keys:h,mustBeExact:p},children:f,paramParsers:l}};return function(n,r,t){function a(n){w=n.map(C);for(var r in T)delete T[r];A.forEach(function(n){n.reset(),T[n.name]=n.get,e(w,n)})}function o(e,n){for(y.forEach(function(r){r(e,n,j)}),k.forEach(function(r){null!=r&&r(e,n,j)});R.length;)R.pop()(e,n,j);E.forEach(function(r){r(e,n,j)})}function i(e,r){b=void 0,h&&h.set(e),e.redirectTo&&!g||($.response=e,$.navigation=r,o(e,r)),e.redirectTo&&n.replace(e.redirectTo)}void 0===t&&(t={});var u=t,c=u.addons,s=void 0===c?[]:c,l=u.sideEffects,f=void 0===l?[]:l,h=u.cache,v=u.pathnameOptions,m=u.emitRedirects,g=void 0===m||m,y=[],E=[];f.forEach(function(e){e.after?E.push(e.fn):y.push(e.fn)});var b,w=[],T={},A=s.concat(p(v)),k=[],R=[],$={response:null,navigation:null};a(r),n.respondWith(function(e){b&&(b.cancel(e.action),b.cancelled=!0),b=e;var n={action:e.action,previous:$.response};if(h){var r=h.get(e.location);null!=r&&i(r,n)}d(e.location,w).then(function(r){e.cancelled||(e.finish(),i(x(r,T),n))})});var j={addons:T,history:n,respond:function(e,n){if("function"!=typeof e)throw new Error('The first argument passed to "respond" must be a function');var r=(n||{}).once;if(void 0===r||!r){$.response&&e.call(null,$.response,$.navigation,j);var t=k.push(e);return function(){k[t-1]=null}}$.response?e.call(null,$.response,$.navigation,j):R.push(e)},refresh:a,current:function(){return{response:$.response,navigation:$.navigation}}};return j}}(); | ||
var Curi=function(){"use strict";function e(n,r,t){n.forEach(function(n){var i=r.register(n.public,t);e(n.children,r,i)})}function n(e,n){for(var r,a=[],o=0,u=0,c="",s=n&&n.delimiter||k,l=n&&n.delimiters||R,p=!1;null!==(r=$.exec(e));){var f=r[0],h=r[1],v=r.index;if(c+=e.slice(u,v),u=v+f.length,h)c+=h[1],p=!0;else{var d="",m=e[u],g=r[2],y=r[3],x=r[4],E=r[5];if(!p&&c.length){var b=c.length-1;l.indexOf(c[b])>-1&&(d=c[b],c=c.slice(0,b))}c&&(a.push(c),c="",p=!1);var w=""!==d&&void 0!==m&&m!==d,T="+"===E||"*"===E,A="?"===E||"*"===E,j=d||s,O=y||x;a.push({name:g||o++,prefix:d,delimiter:j,optional:A,repeat:T,partial:w,pattern:O?i(O):"[^"+t(j)+"]+?"})}}return(c||u<e.length)&&a.push(c+e.substr(u)),a}function r(e){for(var n=new Array(e.length),r=0;r<e.length;r++)"object"==typeof e[r]&&(n[r]=new RegExp("^(?:"+e[r].pattern+")$"));return function(r,t){for(var i="",a=t&&t.encode||encodeURIComponent,o=0;o<e.length;o++){var u=e[o];if("string"!=typeof u){var c,s=r?r[u.name]:void 0;if(Array.isArray(s)){if(!u.repeat)throw new TypeError('Expected "'+u.name+'" to not repeat, but got array');if(0===s.length){if(u.optional)continue;throw new TypeError('Expected "'+u.name+'" to not be empty')}for(var l=0;l<s.length;l++){if(c=a(s[l]),!n[o].test(c))throw new TypeError('Expected all "'+u.name+'" to match "'+u.pattern+'"');i+=(0===l?u.prefix:u.delimiter)+c}}else if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s){if(!u.optional)throw new TypeError('Expected "'+u.name+'" to be '+(u.repeat?"an array":"a string"));u.partial&&(i+=u.prefix)}else{if(c=a(String(s)),!n[o].test(c))throw new TypeError('Expected "'+u.name+'" to match "'+u.pattern+'", but got "'+c+'"');i+=u.prefix+c}}else i+=u}return i}}function t(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function i(e){return e.replace(/([=!:$/()])/g,"\\$1")}function a(e){return e&&e.sensitive?"":"i"}function o(e,n){if(!n)return e;var r=e.source.match(/\((?!\?)/g);if(r)for(var t=0;t<r.length;t++)n.push({name:t,prefix:null,delimiter:null,optional:!1,repeat:!1,partial:!1,pattern:null});return e}function u(e,n,r){for(var t=[],i=0;i<e.length;i++)t.push(l(e[i],n,r).source);return new RegExp("(?:"+t.join("|")+")",a(r))}function c(e,r,t){return s(n(e,t),r,t)}function s(e,n,r){for(var i=(r=r||{}).strict,o=!1!==r.end,u=t(r.delimiter||k),c=r.delimiters||R,s=[].concat(r.endsWith||[]).map(t).concat("$").join("|"),l="",p=!1,f=0;f<e.length;f++){var h=e[f];if("string"==typeof h)l+=t(h),p=f===e.length-1&&c.indexOf(h[h.length-1])>-1;else{var v=t(h.prefix),d=h.repeat?"(?:"+h.pattern+")(?:"+v+"(?:"+h.pattern+"))*":h.pattern;n&&n.push(h),h.optional?h.partial?l+=v+"("+d+")?":l+="(?:"+v+"("+d+"))?":l+=v+"("+d+")"}}return o?(i||(l+="(?:"+u+")?"),l+="$"===s?"$":"(?="+s+")"):(i||(l+="(?:"+u+"(?="+s+"))?"),p||(l+="(?="+u+"|"+s+")")),new RegExp("^"+l,a(r))}function l(e,n,r){return e instanceof RegExp?o(e,n):Array.isArray(e)?u(e,n,r):c(e,n,r)}function p(e){var n={},r={};return{name:"pathname",register:function(e,r){var t=e.name,i=e.path;void 0!==n[t]&&console.warn('A pathname with the name "'+t+'" already exists. Each route shouldhave a unique name. By registering a pathname with a name that already exists, you are overwriting the existing pathname. This may break your application.');var a;return r&&n[r]&&(a=n[r]),n[t]=a?B(a,i):i,t},get:function(t,i){if(null!=n[t]){var a=r[t]?r[t]:r[t]=b.compile(n[t]);return j(a(i,e))}console.error("Could not generate pathname for "+t+" because it is not registered.")},reset:function(){n={},r={}}}}function f(e,n,r,t){var i=O(n),a=e.match,o=a.re,u=a.keys,c=a.mustBeExact,s=e.children,l=o.exec(i);if(!l)return!1;var p=l[0],h=l.slice(1),v={};u.forEach(function(e,n){v[e.name]=h[n]});var d=null!=t?B(t,p):j(p);if(r.push({route:e,params:v}),!s||!s.length)return!0;var m=i.slice(p.length),g=!!m.length,y=s.some(function(e){return f(e,m,r,d)});return!(c&&g&&!y)||(r.pop(),!1)}function h(e,n){if(!n)return e;var r={};for(var t in e){var i=e[t],a=n[t];if(a)try{i=a(i)}catch(n){console.error(n),i=e[t]}r[t]=i}return r}function v(e,n){return{params:n.params,location:n.location,name:e.public.name}}function d(e,n){var r,t=[],i=[],a={};if(n.some(function(n){return f(n,e.pathname,t)}),t.length){var o=t.pop();t.forEach(function(e){i.push(e.route.public.name),Object.assign(a,h(e.params,e.route.paramParsers))}),r=o.route,Object.assign(a,h(o.params,r.paramParsers))}return m(r,{location:e,params:a,partials:i,status:null!=r?200:404,body:void 0,data:void 0,title:""})}function m(e,n){if(!e)return Promise.resolve({route:e,props:n});var r=e.public.match;return Promise.all([r.initial?r.initial():void 0,r.every?r.every(v(e,n)):void 0]).then(function(r){var t=r[0],i=r[1];return{route:e,props:n,error:null,resolved:{initial:t,every:i}}},function(r){return{route:e,props:n,error:r,resolved:null}})}function g(e){return{redirect:function(n,r){void 0===r&&(r=301),e.status=r,e.redirectTo=n},error:function(n){e.error=n},status:function(n){e.status=n},data:function(n){e.data=n},body:function(n){e.body=n},title:function(n){e.title=n}}}function y(e,n){return Object.assign({key:n.location.key,name:e?e.public.name:void 0},n)}function x(e,n){var r=e.error,t=e.resolved,i=e.route,a=e.props;return i&&i.public.match.response&&i.public.match.response({error:r,resolved:t,route:v(i,a),set:g(a),addons:n}),y(i,a)}function E(e){var n=null,r=!1;return function(){return r?n:(n=e(),r=!0,n)}}var b=l,w=n,T=r,A=s,k="/",R="./",$=new RegExp(["(\\\\.)","(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?"].join("|"),"g");b.parse=w,b.compile=function(e,t){return r(n(e,t))},b.tokensToFunction=T,b.tokensToRegExp=A;var j=function(e){return"/"===e.charAt(0)?e:"/"+e},O=function(e){return"/"===e.charAt(0)?e.slice(1):e},P=function(e){return"/"===e.charAt(e.length-1)?e:e+"/"},B=function(e,n){return P(e)+n},C=function(e){var n=e.name,r=e.path,t=e.pathOptions,i=void 0===t?{}:t,a=e.children,o=void 0===a?[]:a,u=e.match,c=void 0===u?{}:u,s=e.extra,l=e.params,p=null==i.end||i.end,f=[];o.length&&(i.end=!1,f=o.map(C));var h=[],v=b(r,h,i);return{public:{name:n,path:r,keys:h.map(function(e){return e.name}),match:{initial:c.initial&&E(c.initial),every:c.every,response:c.response},extra:s},match:{re:v,keys:h,mustBeExact:p},children:f,paramParsers:l}};return function(n,r,t){function i(n){w=n.map(C);for(var r in T)delete T[r];A.forEach(function(n){n.reset(),T[n.name]=n.get,e(w,n)})}function a(e,n){for(y.forEach(function(r){r(e,n,j)}),k.forEach(function(r){null!=r&&r(e,n,j)});R.length;)R.pop()(e,n,j);E.forEach(function(r){r(e,n,j)})}function o(e,r){b=void 0,h&&h.set(e),e.redirectTo&&!g||($.response=e,$.navigation=r,a(e,r)),e.redirectTo&&n.replace(e.redirectTo)}void 0===t&&(t={});var u=t,c=u.addons,s=void 0===c?[]:c,l=u.sideEffects,f=void 0===l?[]:l,h=u.cache,v=u.pathnameOptions,m=u.emitRedirects,g=void 0===m||m,y=[],E=[];f.forEach(function(e){e.after?E.push(e.fn):y.push(e.fn)});var b,w=[],T={},A=s.concat(p(v)),k=[],R=[],$={response:null,navigation:null};i(r),n.respondWith(function(e){b&&(b.cancel(e.action),b.cancelled=!0),b=e;var n={action:e.action,previous:$.response};if(h){var r=h.get(e.location);null!=r&&o(r,n)}d(e.location,w).then(function(r){e.cancelled||(e.finish(),o(x(r,T),n))})});var j={addons:T,history:n,respond:function(e,n){if("function"!=typeof e)throw new Error('The first argument passed to "respond" must be a function');var r=n||{},t=r.once,i=void 0!==t&&t,a=r.initial,o=void 0===a||a;if(!i){$.response&&o&&e.call(null,$.response,$.navigation,j);var u=k.push(e);return function(){k[u-1]=null}}$.response&&o?e.call(null,$.response,$.navigation,j):R.push(e)},refresh:i,current:function(){return{response:$.response,navigation:$.navigation}}};return j}}(); |
{ | ||
"name": "@curi/core", | ||
"version": "1.0.0-beta.24", | ||
"version": "1.0.0-beta.25", | ||
"description": "A JavaScript router that doesn't care how you render", | ||
@@ -5,0 +5,0 @@ "main": "dist/curi.common.js", |
@@ -13,2 +13,3 @@ import { History, HickoryLocation, Action } from "@hickory/root"; | ||
once?: boolean; | ||
initial?: boolean; | ||
} | ||
@@ -15,0 +16,0 @@ export declare type RemoveResponseHandler = () => void; |
79912
1770