atomic-router
Advanced tools
Comparing version 0.4.0-dev.1 to 0.4.0
@@ -999,2 +999,3 @@ 'use strict'; | ||
var setHistory = effector.createEvent(); | ||
var routeNotFound = effector.createEvent(); | ||
var $query = effector.createStore({}); | ||
@@ -1087,9 +1088,18 @@ var $path = effector.createStore(''); | ||
target: recalculateFx | ||
}); // Trigger 404 if no routes were entered | ||
effector.guard({ | ||
clock: recalculateFx.doneData, | ||
filter: function filter(_ref7) { | ||
var entered = _ref7.entered; | ||
return entered.length === 0; | ||
}, | ||
target: routeNotFound | ||
}); | ||
var routesEntered = recalculateFx.doneData.map(function (_ref7) { | ||
var entered = _ref7.entered; | ||
var routesEntered = recalculateFx.doneData.map(function (_ref8) { | ||
var entered = _ref8.entered; | ||
return entered; | ||
}); | ||
var routesLeft = recalculateFx.doneData.map(function (_ref8) { | ||
var left = _ref8.left; | ||
var routesLeft = recalculateFx.doneData.map(function (_ref9) { | ||
var left = _ref9.left; | ||
return left; | ||
@@ -1103,5 +1113,5 @@ }); | ||
clock: routeObj.route.navigate.doneData, | ||
fn: function fn(_ref12) { | ||
var params = _ref12.params, | ||
query = _ref12.query; | ||
fn: function fn(_ref13) { | ||
var params = _ref13.params, | ||
query = _ref13.query; | ||
return { | ||
@@ -1162,4 +1172,4 @@ route: routeObj, | ||
effect: function () { | ||
var _effect = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref9) { | ||
var history, _ref10, path, query; | ||
var _effect = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref10) { | ||
var history, _ref11, path, query; | ||
@@ -1170,5 +1180,5 @@ return runtime_1.wrap(function _callee$(_context) { | ||
case 0: | ||
history = _ref9.history; | ||
_ref10 = [history.location.pathname, Object.fromEntries( // @ts-expect-error | ||
new URLSearchParams(history.location.search))], path = _ref10[0], query = _ref10[1]; | ||
history = _ref10.history; | ||
_ref11 = [history.location.pathname, Object.fromEntries( // @ts-expect-error | ||
new URLSearchParams(history.location.search))], path = _ref11[0], query = _ref11[1]; | ||
return _context.abrupt("return", { | ||
@@ -1204,3 +1214,3 @@ path: path, | ||
effect: function () { | ||
var _effect2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref11) { | ||
var _effect2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref12) { | ||
var history, scopedRecheck; | ||
@@ -1211,3 +1221,3 @@ return runtime_1.wrap(function _callee2$(_context2) { | ||
case 0: | ||
history = _ref11.history; | ||
history = _ref12.history; | ||
scopedRecheck = recheckFx; | ||
@@ -1260,3 +1270,4 @@ | ||
push: pushFx, | ||
routes: remappedRoutes | ||
routes: remappedRoutes, | ||
routeNotFound: routeNotFound | ||
}; | ||
@@ -1263,0 +1274,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("effector"),r=require("path-to-regexp");function e(t,r,e,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function u(t){e(i,o,a,u,c,"next",t)}function c(t){e(i,o,a,u,c,"throw",t)}u(void 0)}))}}function o(){return(o=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function a(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function i(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return a(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,c=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof h?r:h).prototype),a=new L(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(e.method=o,e.arg=a;;){var i=e.delegate;if(i){var u=b(i,e);if(u){if(u===s)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=f(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,a),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var s={};function h(){}function p(){}function l(){}var y={};u(y,o,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(O([])));v&&v!==r&&e.call(v,o)&&(y=v);var m=l.prototype=h.prototype=Object.create(y);function g(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function w(t,r){var n;this._invoke=function(o,a){function i(){return new r((function(n,i){!function n(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&e.call(h,"__await")?r.resolve(h.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):r.resolve(h).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return s;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=f(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,s;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,s):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,s)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return a.next=a}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=l,u(m,"constructor",l),u(l,"constructor",p),p.displayName=u(l,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,u(t,i,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},g(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(r,e,n,o,a){void 0===a&&(a=Promise);var i=new w(c(r,e,n,o),a);return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(m),u(m,i,"Generator"),u(m,o,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return i.type="throw",i.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=e.call(a,"catchLoc"),c=e.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),s},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),s}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:O(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),s}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}}(u={exports:{}}),u.exports);function f(t){var e=t.params,n=t.query;return r.compile(t.pathCreator)(e)+(Object.keys(n).length?"?"+new URLSearchParams(n):"")}function s(t){var e=t.actualPath,n=r.match(t.pathCreator)(e);return n?{matches:!0,params:n.params}:{matches:!1}}var h=t.createEffect((function(t){if(!t.history)throw new Error("[Routing] No history provided");return t.history[t.method](t.path,{}),t}));exports.buildPath=f,exports.createHistoryRouter=function(r){var e=function(t){for(var r,e=[],n=function(){var t=r.value;Array.isArray(t.route)?e.push.apply(e,t.route.map((function(r){return o({},t,{route:r})}))):e.push(t)},a=i(t);!(r=a()).done;)n();return e}(r.routes),a=t.createEvent(),u=t.createStore({}),p=t.createStore(""),l=t.createStore([]),y=t.createStore(null).on(a,(function(t,r){return r})),d=t.attach({source:{history:y},effect:h,mapParams:function(t,r){return o({history:r.history},t)}}),v=t.createEffect((function(t){var r=t.params,e=t.query;return{path:f({pathCreator:t.route.path,params:r,query:e}),params:r,query:e,method:"push"}})),m=t.createEffect((function(t){for(var r,n=t.path,o=t.query,a=[],u=[],c=i(e);!(r=c()).done;){var f=r.value,h=s({pathCreator:f.path,actualPath:n});(h.matches?a:u).push({route:f,params:h.params,query:o})}return{entered:a,left:u}}));p.on(m.done,(function(t,r){return r.params.path})),u.on(m.done,(function(t,r){return r.params.query})),l.on(m.doneData,(function(t,r){return r.entered.map((function(t){return t.route.route}))})),t.sample({clock:v.doneData,target:d}),t.sample({clock:d.doneData,target:m});for(var g,w=m.doneData.map((function(t){return t.entered})),b=m.doneData.map((function(t){return t.left})),x=function(){var r=g.value;t.sample({clock:r.route.navigate.doneData,fn:function(t){return{route:r,params:t.params,query:t.query}},target:v}),t.guard({clock:w.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened.map((function(t){return t})),target:r.route.updated}),t.guard({clock:w.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened.map((function(t){return!t})),target:r.route.opened}),t.guard({clock:b.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened,target:r.route.left})},E=i(e);!(g=E()).done;)x();var L,O=t.attach({source:{history:y},effect:(L=n(c.mark((function t(r){var e,n;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=[(e=r.history).location.pathname,Object.fromEntries(new URLSearchParams(e.location.search))],t.abrupt("return",{path:n[0],query:n[1]});case 3:case"end":return t.stop()}}),t)}))),function(t){return L.apply(this,arguments)})});t.sample({source:O.doneData,target:m});var k,S=t.attach({source:{history:y},effect:(k=n(c.mark((function r(e){var n,o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.history,o=O;try{o=t.scopeBind(O)}catch(t){}return n.listen((function(){o()})),r.abrupt("return",!0);case 5:case"end":return r.stop()}}),r)}))),function(t){return k.apply(this,arguments)})});return r.hydrate||t.sample({clock:S.doneData,target:O}),t.sample({clock:y,target:S}),{$path:p,$query:u,$activeRoutes:l,$history:y,setHistory:a,push:d,routes:e}},exports.createRoute=function(){var r=t.createEffect(function(){var t=n(c.mark((function t(r){return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",{params:r.params||{},query:r.query||{}});case 2:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}()),e=t.attach({effect:r,mapParams:function(t){return{params:t||{},query:{}}}}),o=t.createStore(!1),a=t.createStore({}),i=t.createStore({}),u=t.createEvent(),f=t.createEvent(),s=t.createEvent();return o.on(u,(function(){return!0})).on(s,(function(){return!1})),a.on(u,(function(t,r){return r.params})).on(f,(function(t,r){return r.params})),i.on(u,(function(t,r){return r.query})).on(f,(function(t,r){return r.query})),t.sample({clock:r.doneData,target:u}),{$isOpened:o,$params:a,$query:i,opened:u,updated:f,left:s,navigate:r,open:e}},exports.matchPath=s; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("effector"),r=require("path-to-regexp");function e(t,r,e,n,o,a,i){try{var u=t[a](i),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}function n(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function u(t){e(i,o,a,u,c,"next",t)}function c(t){e(i,o,a,u,c,"throw",t)}u(void 0)}))}}function o(){return(o=Object.assign||function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function a(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function i(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return a(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?a(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,c=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function c(t,r,e,n){var o=Object.create((r&&r.prototype instanceof h?r:h).prototype),a=new L(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(e.method=o,e.arg=a;;){var i=e.delegate;if(i){var u=b(i,e);if(u){if(u===s)continue;return u}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var c=f(t,r,e);if("normal"===c.type){if(n=e.done?"completed":"suspendedYield",c.arg===s)continue;return{value:c.arg,done:e.done}}"throw"===c.type&&(n="completed",e.method="throw",e.arg=c.arg)}}}(t,e,a),o}function f(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var s={};function h(){}function p(){}function l(){}var y={};u(y,o,(function(){return this}));var d=Object.getPrototypeOf,v=d&&d(d(O([])));v&&v!==r&&e.call(v,o)&&(y=v);var m=l.prototype=h.prototype=Object.create(y);function g(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function w(t,r){var n;this._invoke=function(o,a){function i(){return new r((function(n,i){!function n(o,a,i,u){var c=f(t[o],t,a);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&e.call(h,"__await")?r.resolve(h.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):r.resolve(h).then((function(t){s.value=t,i(s)}),(function(t){return n("throw",t,i,u)}))}u(c.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return s;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var n=f(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,s;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,s):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,s)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function E(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return a.next=a}}return{next:k}}function k(){return{value:void 0,done:!0}}return p.prototype=l,u(m,"constructor",l),u(l,"constructor",p),p.displayName=u(l,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,l):(t.__proto__=l,u(t,i,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},g(w.prototype),u(w.prototype,a,(function(){return this})),t.AsyncIterator=w,t.async=function(r,e,n,o,a){void 0===a&&(a=Promise);var i=new w(c(r,e,n,o),a);return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},g(m),u(m,i,"Generator"),u(m,o,(function(){return this})),u(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function n(e,n){return i.type="throw",i.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=e.call(a,"catchLoc"),c=e.call(a,"finallyLoc");if(u&&c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,s):this.complete(i)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),s},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),E(e),s}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;E(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:O(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),s}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}}(u={exports:{}}),u.exports);function f(t){var e=t.params,n=t.query;return r.compile(t.pathCreator)(e)+(Object.keys(n).length?"?"+new URLSearchParams(n):"")}function s(t){var e=t.actualPath,n=r.match(t.pathCreator)(e);return n?{matches:!0,params:n.params}:{matches:!1}}var h=t.createEffect((function(t){if(!t.history)throw new Error("[Routing] No history provided");return t.history[t.method](t.path,{}),t}));exports.buildPath=f,exports.createHistoryRouter=function(r){var e=function(t){for(var r,e=[],n=function(){var t=r.value;Array.isArray(t.route)?e.push.apply(e,t.route.map((function(r){return o({},t,{route:r})}))):e.push(t)},a=i(t);!(r=a()).done;)n();return e}(r.routes),a=t.createEvent(),u=t.createEvent(),p=t.createStore({}),l=t.createStore(""),y=t.createStore([]),d=t.createStore(null).on(a,(function(t,r){return r})),v=t.attach({source:{history:d},effect:h,mapParams:function(t,r){return o({history:r.history},t)}}),m=t.createEffect((function(t){var r=t.params,e=t.query;return{path:f({pathCreator:t.route.path,params:r,query:e}),params:r,query:e,method:"push"}})),g=t.createEffect((function(t){for(var r,n=t.path,o=t.query,a=[],u=[],c=i(e);!(r=c()).done;){var f=r.value,h=s({pathCreator:f.path,actualPath:n});(h.matches?a:u).push({route:f,params:h.params,query:o})}return{entered:a,left:u}}));l.on(g.done,(function(t,r){return r.params.path})),p.on(g.done,(function(t,r){return r.params.query})),y.on(g.doneData,(function(t,r){return r.entered.map((function(t){return t.route.route}))})),t.sample({clock:m.doneData,target:v}),t.sample({clock:v.doneData,target:g}),t.guard({clock:g.doneData,filter:function(t){return 0===t.entered.length},target:u});for(var w,b=g.doneData.map((function(t){return t.entered})),x=g.doneData.map((function(t){return t.left})),E=function(){var r=w.value;t.sample({clock:r.route.navigate.doneData,fn:function(t){return{route:r,params:t.params,query:t.query}},target:m}),t.guard({clock:b.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened.map((function(t){return t})),target:r.route.updated}),t.guard({clock:b.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened.map((function(t){return!t})),target:r.route.opened}),t.guard({clock:x.filterMap((function(t){return t.find((function(t){return t.route===r}))})),filter:r.route.$isOpened,target:r.route.left})},L=i(e);!(w=L()).done;)E();var O,k=t.attach({source:{history:d},effect:(O=n(c.mark((function t(r){var e,n;return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=[(e=r.history).location.pathname,Object.fromEntries(new URLSearchParams(e.location.search))],t.abrupt("return",{path:n[0],query:n[1]});case 3:case"end":return t.stop()}}),t)}))),function(t){return O.apply(this,arguments)})});t.sample({source:k.doneData,target:g});var S,j=t.attach({source:{history:d},effect:(S=n(c.mark((function r(e){var n,o;return c.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:n=e.history,o=k;try{o=t.scopeBind(k)}catch(t){}return n.listen((function(){o()})),r.abrupt("return",!0);case 5:case"end":return r.stop()}}),r)}))),function(t){return S.apply(this,arguments)})});return r.hydrate||t.sample({clock:j.doneData,target:k}),t.sample({clock:d,target:j}),{$path:l,$query:p,$activeRoutes:y,$history:d,setHistory:a,push:v,routes:e,routeNotFound:u}},exports.createRoute=function(){var r=t.createEffect(function(){var t=n(c.mark((function t(r){return c.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",{params:r.params||{},query:r.query||{}});case 2:case"end":return t.stop()}}),t)})));return function(r){return t.apply(this,arguments)}}()),e=t.attach({effect:r,mapParams:function(t){return{params:t||{},query:{}}}}),o=t.createStore(!1),a=t.createStore({}),i=t.createStore({}),u=t.createEvent(),f=t.createEvent(),s=t.createEvent();return o.on(u,(function(){return!0})).on(s,(function(){return!1})),a.on(u,(function(t,r){return r.params})).on(f,(function(t,r){return r.params})),i.on(u,(function(t,r){return r.query})).on(f,(function(t,r){return r.query})),t.sample({clock:r.doneData,target:u}),{$isOpened:o,$params:a,$query:i,opened:u,updated:f,left:s,navigate:r,open:e}},exports.matchPath=s; | ||
//# sourceMappingURL=atomic-router.cjs.production.min.js.map |
@@ -995,2 +995,3 @@ import { createEffect, attach, createStore, createEvent, sample, guard, scopeBind } from 'effector'; | ||
var setHistory = createEvent(); | ||
var routeNotFound = createEvent(); | ||
var $query = createStore({}); | ||
@@ -1083,9 +1084,18 @@ var $path = createStore(''); | ||
target: recalculateFx | ||
}); // Trigger 404 if no routes were entered | ||
guard({ | ||
clock: recalculateFx.doneData, | ||
filter: function filter(_ref7) { | ||
var entered = _ref7.entered; | ||
return entered.length === 0; | ||
}, | ||
target: routeNotFound | ||
}); | ||
var routesEntered = recalculateFx.doneData.map(function (_ref7) { | ||
var entered = _ref7.entered; | ||
var routesEntered = recalculateFx.doneData.map(function (_ref8) { | ||
var entered = _ref8.entered; | ||
return entered; | ||
}); | ||
var routesLeft = recalculateFx.doneData.map(function (_ref8) { | ||
var left = _ref8.left; | ||
var routesLeft = recalculateFx.doneData.map(function (_ref9) { | ||
var left = _ref9.left; | ||
return left; | ||
@@ -1099,5 +1109,5 @@ }); | ||
clock: routeObj.route.navigate.doneData, | ||
fn: function fn(_ref12) { | ||
var params = _ref12.params, | ||
query = _ref12.query; | ||
fn: function fn(_ref13) { | ||
var params = _ref13.params, | ||
query = _ref13.query; | ||
return { | ||
@@ -1158,4 +1168,4 @@ route: routeObj, | ||
effect: function () { | ||
var _effect = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref9) { | ||
var history, _ref10, path, query; | ||
var _effect = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(_ref10) { | ||
var history, _ref11, path, query; | ||
@@ -1166,5 +1176,5 @@ return runtime_1.wrap(function _callee$(_context) { | ||
case 0: | ||
history = _ref9.history; | ||
_ref10 = [history.location.pathname, Object.fromEntries( // @ts-expect-error | ||
new URLSearchParams(history.location.search))], path = _ref10[0], query = _ref10[1]; | ||
history = _ref10.history; | ||
_ref11 = [history.location.pathname, Object.fromEntries( // @ts-expect-error | ||
new URLSearchParams(history.location.search))], path = _ref11[0], query = _ref11[1]; | ||
return _context.abrupt("return", { | ||
@@ -1200,3 +1210,3 @@ path: path, | ||
effect: function () { | ||
var _effect2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref11) { | ||
var _effect2 = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(_ref12) { | ||
var history, scopedRecheck; | ||
@@ -1207,3 +1217,3 @@ return runtime_1.wrap(function _callee2$(_context2) { | ||
case 0: | ||
history = _ref11.history; | ||
history = _ref12.history; | ||
scopedRecheck = recheckFx; | ||
@@ -1256,3 +1266,4 @@ | ||
push: pushFx, | ||
routes: remappedRoutes | ||
routes: remappedRoutes, | ||
routeNotFound: routeNotFound | ||
}; | ||
@@ -1259,0 +1270,0 @@ }; |
@@ -29,3 +29,4 @@ import { History } from 'history'; | ||
routes: RouteObject<any>[]; | ||
routeNotFound: import("effector").Event<void>; | ||
}; | ||
export {}; |
{ | ||
"version": "0.4.0-dev.1", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -4,0 +4,0 @@ "main": "dist/index.js", |
@@ -74,2 +74,3 @@ import { buildPath, matchPath } from './build-path'; | ||
const setHistory = createEvent<History>(); | ||
const routeNotFound = createEvent(); | ||
@@ -167,2 +168,9 @@ const $query = createStore({}); | ||
// Trigger 404 if no routes were entered | ||
guard({ | ||
clock: recalculateFx.doneData, | ||
filter: ({ entered }) => entered.length === 0, | ||
target: routeNotFound, | ||
}); | ||
const routesEntered = recalculateFx.doneData.map(({ entered }) => entered); | ||
@@ -283,3 +291,4 @@ const routesLeft = recalculateFx.doneData.map(({ left }) => left); | ||
routes: remappedRoutes, | ||
routeNotFound, | ||
}; | ||
}; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
289316
2683