Socket
Socket
Sign inDemoInstall

redux-first-routing

Package Overview
Dependencies
12
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.0 to 0.2.1

38

dist/redux-first-routing.js

@@ -203,6 +203,10 @@ (function (global, factory) {

var stripPrefix = exports.stripPrefix = function stripPrefix(path, prefix) {
return path.indexOf(prefix) === 0 ? path.substr(prefix.length) : path;
var hasBasename = exports.hasBasename = function hasBasename(path, prefix) {
return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path);
};
var stripBasename = exports.stripBasename = function stripBasename(path, prefix) {
return hasBasename(path, prefix) ? path.substr(prefix.length) : path;
};
var stripTrailingSlash = exports.stripTrailingSlash = function stripTrailingSlash(path) {

@@ -229,4 +233,2 @@ return path.charAt(path.length - 1) === '/' ? path.slice(0, -1) : path;

pathname = decodeURI(pathname);
return {

@@ -245,3 +247,3 @@ pathname: pathname,

var path = encodeURI(pathname || '/');
var path = pathname || '/';

@@ -303,4 +305,14 @@ if (search && search !== '?') path += search.charAt(0) === '?' ? search : '?' + search;

location.key = key;
try {
location.pathname = decodeURI(location.pathname);
} catch (e) {
if (e instanceof URIError) {
throw new URIError('Pathname "' + location.pathname + '" could not be decoded. ' + 'This is likely caused by an invalid percent-encoding.');
} else {
throw e;
}
}
if (key) location.key = key;
if (currentLocation) {

@@ -313,2 +325,7 @@ // Resolve incomplete/relative pathname relative to current location.

}
} else {
// When there is no prior location and pathname is empty, set it to /
if (!location.pathname) {
location.pathname = '/';
}
}

@@ -547,8 +564,7 @@

if (basename) path = (0, PathUtils.stripPrefix)(path, basename);
(0, _warning2.default)(!basename || (0, PathUtils.hasBasename)(path, basename), 'You are attempting to use a basename on a page whose URL path does not begin ' + 'with the basename. Expected path "' + path + '" to begin with "' + basename + '".');
return _extends({}, (0, PathUtils.parsePath)(path), {
state: state,
key: key
});
if (basename) path = (0, PathUtils.stripBasename)(path, basename);
return (0, LocationUtils.createLocation)(path, state, key);
};

@@ -555,0 +571,0 @@

@@ -1,1 +0,1 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.ReduxFirstRouting=t.ReduxFirstRouting||{})}(this,function(t){"use strict";function e(t,e){return e={exports:{}},t(e,e.exports),e.exports}function n(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function r(t){var e;switch(t.arrayFormat){case"index":return function(t,n,r){e=/\[(\d*)\]$/.exec(t),t=t.replace(/\[\d*\]$/,""),e?(void 0===r[t]&&(r[t]={}),r[t][e[1]]=n):r[t]=n};case"bracket":return function(t,n,r){e=/(\[\])$/.exec(t),t=t.replace(/\[\]$/,""),e?void 0!==r[t]?r[t]=[].concat(r[t],n):r[t]=[n]:r[t]=n};default:return function(t,e,n){void 0!==n[t]?n[t]=[].concat(n[t],e):n[t]=e}}}function o(t){return Array.isArray(t)?t.sort():"object"==typeof t?o(Object.keys(t)).sort(function(t,e){return Number(t)-Number(e)}).map(function(e){return t[e]}):t}function a(t,e){e.dispatch(S({pathname:t.location.pathname,search:t.location.search,hash:t.location.hash})),t.listen(function(t){e.dispatch(S({pathname:t.pathname,search:t.search,hash:t.hash}))})}var i=function(){},u=function(t,e,n,r,o,a,i,u){if(!t){var s;if(void 0===e)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,a,i,u],f=0;(s=new Error(e.replace(/%s/g,function(){return c[f++]}))).name="Invariant Violation"}throw s.framesToPop=1,s}},s=function(t){return"/"===t.charAt(0)},c=function(t,e){for(var n=e,r=n+1,o=t.length;r<o;n+=1,r+=1)t[n]=t[r];t.pop()},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=t&&t.split("/")||[],r=e&&e.split("/")||[],o=t&&s(t),a=e&&s(e),i=o||a;if(t&&s(t)?r=n:n.length&&(r.pop(),r=r.concat(n)),!r.length)return"/";var u=void 0;if(r.length){var f=r[r.length-1];u="."===f||".."===f||""===f}else u=!1;for(var l=0,d=r.length;d>=0;d--){var h=r[d];"."===h?c(r,d):".."===h?(c(r,d),l++):l&&(c(r,d),l--)}if(!i)for(;l--;l)r.unshift("..");!i||""===r[0]||r[0]&&s(r[0])||r.unshift("");var p=r.join("/");return u&&"/"!==p.substr(-1)&&(p+="/"),p},l=e(function(t,e){e.__esModule=!0;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=function t(e,r){if(e===r)return!0;if(null==e||null==r)return!1;if(Array.isArray(e))return Array.isArray(r)&&e.length===r.length&&e.every(function(e,n){return t(e,r[n])});var o=void 0===e?"undefined":n(e);if(o!==(void 0===r?"undefined":n(r)))return!1;if("object"===o){var a=e.valueOf(),i=r.valueOf();if(a!==e||i!==r)return t(a,i);var u=Object.keys(e),s=Object.keys(r);return u.length===s.length&&u.every(function(n){return t(e[n],r[n])})}return!1};e.default=r}),d=e(function(t,e){e.__esModule=!0;e.addLeadingSlash=function(t){return"/"===t.charAt(0)?t:"/"+t},e.stripLeadingSlash=function(t){return"/"===t.charAt(0)?t.substr(1):t},e.stripPrefix=function(t,e){return 0===t.indexOf(e)?t.substr(e.length):t},e.stripTrailingSlash=function(t){return"/"===t.charAt(t.length-1)?t.slice(0,-1):t},e.parsePath=function(t){var e=t||"/",n="",r="",o=e.indexOf("#");-1!==o&&(r=e.substr(o),e=e.substr(0,o));var a=e.indexOf("?");return-1!==a&&(n=e.substr(a),e=e.substr(0,a)),e=decodeURI(e),{pathname:e,search:"?"===n?"":n,hash:"#"===r?"":r}},e.createPath=function(t){var e=t.pathname,n=t.search,r=t.hash,o=encodeURI(e||"/");return n&&"?"!==n&&(o+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(o+="#"===r.charAt(0)?r:"#"+r),o}}),h=e(function(t,e){function n(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0,e.locationsAreEqual=e.createLocation=void 0;var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},o=n(f),a=n(l);e.createLocation=function(t,e,n,a){var i=void 0;return"string"==typeof t?(i=(0,d.parsePath)(t)).state=e:(void 0===(i=r({},t)).pathname&&(i.pathname=""),i.search?"?"!==i.search.charAt(0)&&(i.search="?"+i.search):i.search="",i.hash?"#"!==i.hash.charAt(0)&&(i.hash="#"+i.hash):i.hash="",void 0!==e&&void 0===i.state&&(i.state=e)),i.key=n,a&&(i.pathname?"/"!==i.pathname.charAt(0)&&(i.pathname=(0,o.default)(i.pathname,a.pathname)):i.pathname=a.pathname),i},e.locationsAreEqual=function(t,e){return t.pathname===e.pathname&&t.search===e.search&&t.hash===e.hash&&t.key===e.key&&(0,a.default)(t.state,e.state)}}),p=e(function(t,e){e.__esModule=!0;var n=function(t){return t&&t.__esModule?t:{default:t}}(i),r=function(){var t=null,e=[];return{setPrompt:function(e){return(0,n.default)(null==t,"A history supports only one prompt at a time"),t=e,function(){t===e&&(t=null)}},confirmTransitionTo:function(e,r,o,a){if(null!=t){var i="function"==typeof t?t(e,r):t;"string"==typeof i?"function"==typeof o?o(i,a):((0,n.default)(!1,"A history needs a getUserConfirmation function in order to use a prompt message"),a(!0)):a(!1!==i)}else a(!0)},appendListener:function(t){var n=!0,r=function(){n&&t.apply(void 0,arguments)};return e.push(r),function(){n=!1,e=e.filter(function(t){return t!==r})}},notifyListeners:function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];e.forEach(function(t){return t.apply(void 0,n)})}}};e.default=r}),v=e(function(t,e){e.__esModule=!0;e.canUseDOM=!("undefined"==typeof window||!window.document||!window.document.createElement),e.addEventListener=function(t,e,n){return t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)},e.removeEventListener=function(t,e,n){return t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent("on"+e,n)},e.getConfirmation=function(t,e){return e(window.confirm(t))},e.supportsHistory=function(){var t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)},e.supportsPopStateOnHashChange=function(){return-1===window.navigator.userAgent.indexOf("Trident")},e.supportsGoWithoutReloadUsingHash=function(){return-1===window.navigator.userAgent.indexOf("Firefox")},e.isExtraneousPopstateEvent=function(t){return void 0===t.state&&-1===navigator.userAgent.indexOf("CriOS")}}),y=function(t){return t&&t.__esModule?t.default:t}(e(function(t,e){function n(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},a=n(i),s=n(u),c=n(p),f=function(){try{return window.history.state||{}}catch(t){return{}}},l=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,s.default)(v.canUseDOM,"Browser history needs a DOM");var e=window.history,n=(0,v.supportsHistory)(),i=!(0,v.supportsPopStateOnHashChange)(),u=t.forceRefresh,l=void 0!==u&&u,p=t.getUserConfirmation,y=void 0===p?v.getConfirmation:p,g=t.keyLength,m=void 0===g?6:g,O=t.basename?(0,d.stripTrailingSlash)((0,d.addLeadingSlash)(t.basename)):"",b=function(t){var e=t||{},n=e.key,r=e.state,a=window.location,i=a.pathname+a.search+a.hash;return O&&(i=(0,d.stripPrefix)(i,O)),o({},(0,d.parsePath)(i),{state:r,key:n})},w=function(){return Math.random().toString(36).substr(2,m)},E=(0,c.default)(),A=function(t){o(D,t),D.length=e.length,E.notifyListeners(D.location,D.action)},R=function(t){(0,v.isExtraneousPopstateEvent)(t)||k(b(t.state))},j=function(){k(b(f()))},P=!1,k=function(t){if(P)P=!1,A();else{E.confirmTransitionTo(t,"POP",y,function(e){e?A({action:"POP",location:t}):L(t)})}},L=function(t){var e=D.location,n=x.indexOf(e.key);-1===n&&(n=0);var r=x.indexOf(t.key);-1===r&&(r=0);var o=n-r;o&&(P=!0,U(o))},_=b(f()),x=[_.key],S=function(t){return O+(0,d.createPath)(t)},T=function(t,o){(0,a.default)(!("object"===(void 0===t?"undefined":r(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to push when the 1st argument is a location-like object that already has state; it is ignored");var i=(0,h.createLocation)(t,o,w(),D.location);E.confirmTransitionTo(i,"PUSH",y,function(t){if(t){var r=S(i),o=i.key,u=i.state;if(n)if(e.pushState({key:o,state:u},null,r),l)window.location.href=r;else{var s=x.indexOf(D.location.key),c=x.slice(0,-1===s?0:s+1);c.push(i.key),x=c,A({action:"PUSH",location:i})}else(0,a.default)(void 0===u,"Browser history cannot push state in browsers that do not support HTML5 history"),window.location.href=r}})},C=function(t,o){(0,a.default)(!("object"===(void 0===t?"undefined":r(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to replace when the 1st argument is a location-like object that already has state; it is ignored");var i=(0,h.createLocation)(t,o,w(),D.location);E.confirmTransitionTo(i,"REPLACE",y,function(t){if(t){var r=S(i),o=i.key,u=i.state;if(n)if(e.replaceState({key:o,state:u},null,r),l)window.location.replace(r);else{var s=x.indexOf(D.location.key);-1!==s&&(x[s]=i.key),A({action:"REPLACE",location:i})}else(0,a.default)(void 0===u,"Browser history cannot replace state in browsers that do not support HTML5 history"),window.location.replace(r)}})},U=function(t){e.go(t)},M=function(){return U(-1)},H=function(){return U(1)},G=0,F=function(t){1===(G+=t)?((0,v.addEventListener)(window,"popstate",R),i&&(0,v.addEventListener)(window,"hashchange",j)):0===G&&((0,v.removeEventListener)(window,"popstate",R),i&&(0,v.removeEventListener)(window,"hashchange",j))},N=!1,B=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=E.setPrompt(t);return N||(F(1),N=!0),function(){return N&&(N=!1,F(-1)),e()}},I=function(t){var e=E.appendListener(t);return F(1),function(){F(-1),e()}},D={length:e.length,action:"POP",location:_,createHref:S,push:T,replace:C,go:U,goBack:M,goForward:H,block:B,listen:I};return D};e.default=l})),g=Object.getOwnPropertySymbols,m=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,b=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,o,a=n(t),i=1;i<arguments.length;i++){r=Object(arguments[i]);for(var u in r)m.call(r,u)&&(a[u]=r[u]);if(g){o=g(r);for(var s=0;s<o.length;s++)O.call(r,o[s])&&(a[o[s]]=r[o[s]])}}return a},w=function(t,e){var n=r(e=b({arrayFormat:"none"},e)),a=Object.create(null);return"string"!=typeof t?a:(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;o=void 0===o?null:decodeURIComponent(o),n(decodeURIComponent(r),o,a)}),Object.keys(a).sort().reduce(function(t,e){var n=a[e];return Boolean(n)&&"object"==typeof n&&!Array.isArray(n)?t[e]=o(n):t[e]=n,t},Object.create(null))):a},E="ROUTER/PUSH",A="ROUTER/REPLACE",R="ROUTER/GO",j="ROUTER/GO_BACK",P=function(t){return{type:E,payload:t}},k=function(t){return{type:A,payload:t}},L=function(t){return{type:R,payload:t}},_=function(){return{type:j}},x=function(){return{type:"ROUTER/GO_FORWARD"}},S=function(t){var e=t.pathname,n=t.search,r=t.hash;return{type:"ROUTER/LOCATION_CHANGE",payload:{pathname:e,search:n,queries:w(n),hash:r}}},T=function(t){return function(){return function(e){return function(n){switch(n.type){case E:t.push(n.payload);break;case A:t.replace(n.payload);break;case R:t.go(n.payload);break;case j:t.goBack();break;case"ROUTER/GO_FORWARD":t.goForward();break;default:return e(n)}}}}},C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},U={pathname:"/",search:"",queries:{},hash:""},M=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:U,e=arguments[1];switch(e.type){case"ROUTER/LOCATION_CHANGE":return C({},t,e.payload);default:return t}};t.createBrowserHistory=y,t.startListener=a,t.PUSH=E,t.REPLACE=A,t.GO=R,t.GO_BACK=j,t.GO_FORWARD="ROUTER/GO_FORWARD",t.LOCATION_CHANGE="ROUTER/LOCATION_CHANGE",t.push=P,t.replace=k,t.go=L,t.goBack=_,t.goForward=x,t.locationChange=S,t.routerMiddleware=T,t.routerReducer=M,Object.defineProperty(t,"__esModule",{value:!0})});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.ReduxFirstRouting=t.ReduxFirstRouting||{})}(this,function(t){"use strict";function e(t,e){return e={exports:{}},t(e,e.exports),e.exports}function n(t){if(null===t||void 0===t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function r(t){var e;switch(t.arrayFormat){case"index":return function(t,n,r){e=/\[(\d*)\]$/.exec(t),t=t.replace(/\[\d*\]$/,""),e?(void 0===r[t]&&(r[t]={}),r[t][e[1]]=n):r[t]=n};case"bracket":return function(t,n,r){e=/(\[\])$/.exec(t),t=t.replace(/\[\]$/,""),e?void 0!==r[t]?r[t]=[].concat(r[t],n):r[t]=[n]:r[t]=n};default:return function(t,e,n){void 0!==n[t]?n[t]=[].concat(n[t],e):n[t]=e}}}function o(t){return Array.isArray(t)?t.sort():"object"==typeof t?o(Object.keys(t)).sort(function(t,e){return Number(t)-Number(e)}).map(function(e){return t[e]}):t}function a(t,e){e.dispatch(S({pathname:t.location.pathname,search:t.location.search,hash:t.location.hash})),t.listen(function(t){e.dispatch(S({pathname:t.pathname,search:t.search,hash:t.hash}))})}var i=function(){},u=function(t,e,n,r,o,a,i,u){if(!t){var s;if(void 0===e)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,r,o,a,i,u],f=0;(s=new Error(e.replace(/%s/g,function(){return c[f++]}))).name="Invariant Violation"}throw s.framesToPop=1,s}},s=function(t){return"/"===t.charAt(0)},c=function(t,e){for(var n=e,r=n+1,o=t.length;r<o;n+=1,r+=1)t[n]=t[r];t.pop()},f=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"",n=t&&t.split("/")||[],r=e&&e.split("/")||[],o=t&&s(t),a=e&&s(e),i=o||a;if(t&&s(t)?r=n:n.length&&(r.pop(),r=r.concat(n)),!r.length)return"/";var u=void 0;if(r.length){var f=r[r.length-1];u="."===f||".."===f||""===f}else u=!1;for(var d=0,h=r.length;h>=0;h--){var l=r[h];"."===l?c(r,h):".."===l?(c(r,h),d++):d&&(c(r,h),d--)}if(!i)for(;d--;d)r.unshift("..");!i||""===r[0]||r[0]&&s(r[0])||r.unshift("");var p=r.join("/");return u&&"/"!==p.substr(-1)&&(p+="/"),p},d=e(function(t,e){e.__esModule=!0;var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},r=function t(e,r){if(e===r)return!0;if(null==e||null==r)return!1;if(Array.isArray(e))return Array.isArray(r)&&e.length===r.length&&e.every(function(e,n){return t(e,r[n])});var o=void 0===e?"undefined":n(e);if(o!==(void 0===r?"undefined":n(r)))return!1;if("object"===o){var a=e.valueOf(),i=r.valueOf();if(a!==e||i!==r)return t(a,i);var u=Object.keys(e),s=Object.keys(r);return u.length===s.length&&u.every(function(n){return t(e[n],r[n])})}return!1};e.default=r}),h=e(function(t,e){e.__esModule=!0;e.addLeadingSlash=function(t){return"/"===t.charAt(0)?t:"/"+t},e.stripLeadingSlash=function(t){return"/"===t.charAt(0)?t.substr(1):t};var n=e.hasBasename=function(t,e){return new RegExp("^"+e+"(\\/|\\?|#|$)","i").test(t)};e.stripBasename=function(t,e){return n(t,e)?t.substr(e.length):t},e.stripTrailingSlash=function(t){return"/"===t.charAt(t.length-1)?t.slice(0,-1):t},e.parsePath=function(t){var e=t||"/",n="",r="",o=e.indexOf("#");-1!==o&&(r=e.substr(o),e=e.substr(0,o));var a=e.indexOf("?");return-1!==a&&(n=e.substr(a),e=e.substr(0,a)),{pathname:e,search:"?"===n?"":n,hash:"#"===r?"":r}},e.createPath=function(t){var e=t.pathname,n=t.search,r=t.hash,o=e||"/";return n&&"?"!==n&&(o+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(o+="#"===r.charAt(0)?r:"#"+r),o}}),l=e(function(t,e){function n(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0,e.locationsAreEqual=e.createLocation=void 0;var r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},o=n(f),a=n(d);e.createLocation=function(t,e,n,a){var i=void 0;"string"==typeof t?(i=(0,h.parsePath)(t)).state=e:(void 0===(i=r({},t)).pathname&&(i.pathname=""),i.search?"?"!==i.search.charAt(0)&&(i.search="?"+i.search):i.search="",i.hash?"#"!==i.hash.charAt(0)&&(i.hash="#"+i.hash):i.hash="",void 0!==e&&void 0===i.state&&(i.state=e));try{i.pathname=decodeURI(i.pathname)}catch(t){throw t instanceof URIError?new URIError('Pathname "'+i.pathname+'" could not be decoded. This is likely caused by an invalid percent-encoding.'):t}return n&&(i.key=n),a?i.pathname?"/"!==i.pathname.charAt(0)&&(i.pathname=(0,o.default)(i.pathname,a.pathname)):i.pathname=a.pathname:i.pathname||(i.pathname="/"),i},e.locationsAreEqual=function(t,e){return t.pathname===e.pathname&&t.search===e.search&&t.hash===e.hash&&t.key===e.key&&(0,a.default)(t.state,e.state)}}),p=e(function(t,e){e.__esModule=!0;var n=function(t){return t&&t.__esModule?t:{default:t}}(i),r=function(){var t=null,e=[];return{setPrompt:function(e){return(0,n.default)(null==t,"A history supports only one prompt at a time"),t=e,function(){t===e&&(t=null)}},confirmTransitionTo:function(e,r,o,a){if(null!=t){var i="function"==typeof t?t(e,r):t;"string"==typeof i?"function"==typeof o?o(i,a):((0,n.default)(!1,"A history needs a getUserConfirmation function in order to use a prompt message"),a(!0)):a(!1!==i)}else a(!0)},appendListener:function(t){var n=!0,r=function(){n&&t.apply(void 0,arguments)};return e.push(r),function(){n=!1,e=e.filter(function(t){return t!==r})}},notifyListeners:function(){for(var t=arguments.length,n=Array(t),r=0;r<t;r++)n[r]=arguments[r];e.forEach(function(t){return t.apply(void 0,n)})}}};e.default=r}),v=e(function(t,e){e.__esModule=!0;e.canUseDOM=!("undefined"==typeof window||!window.document||!window.document.createElement),e.addEventListener=function(t,e,n){return t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent("on"+e,n)},e.removeEventListener=function(t,e,n){return t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent("on"+e,n)},e.getConfirmation=function(t,e){return e(window.confirm(t))},e.supportsHistory=function(){var t=window.navigator.userAgent;return(-1===t.indexOf("Android 2.")&&-1===t.indexOf("Android 4.0")||-1===t.indexOf("Mobile Safari")||-1!==t.indexOf("Chrome")||-1!==t.indexOf("Windows Phone"))&&(window.history&&"pushState"in window.history)},e.supportsPopStateOnHashChange=function(){return-1===window.navigator.userAgent.indexOf("Trident")},e.supportsGoWithoutReloadUsingHash=function(){return-1===window.navigator.userAgent.indexOf("Firefox")},e.isExtraneousPopstateEvent=function(t){return void 0===t.state&&-1===navigator.userAgent.indexOf("CriOS")}}),y=function(t){return t&&t.__esModule?t.default:t}(e(function(t,e){function n(t){return t&&t.__esModule?t:{default:t}}e.__esModule=!0;var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},a=n(i),s=n(u),c=n(p),f=function(){try{return window.history.state||{}}catch(t){return{}}},d=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};(0,s.default)(v.canUseDOM,"Browser history needs a DOM");var e=window.history,n=(0,v.supportsHistory)(),i=!(0,v.supportsPopStateOnHashChange)(),u=t.forceRefresh,d=void 0!==u&&u,p=t.getUserConfirmation,y=void 0===p?v.getConfirmation:p,m=t.keyLength,g=void 0===m?6:m,O=t.basename?(0,h.stripTrailingSlash)((0,h.addLeadingSlash)(t.basename)):"",b=function(t){var e=t||{},n=e.key,r=e.state,o=window.location,i=o.pathname+o.search+o.hash;return(0,a.default)(!O||(0,h.hasBasename)(i,O),'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "'+i+'" to begin with "'+O+'".'),O&&(i=(0,h.stripBasename)(i,O)),(0,l.createLocation)(i,r,n)},w=function(){return Math.random().toString(36).substr(2,g)},E=(0,c.default)(),A=function(t){o(D,t),D.length=e.length,E.notifyListeners(D.location,D.action)},R=function(t){(0,v.isExtraneousPopstateEvent)(t)||L(b(t.state))},j=function(){L(b(f()))},k=!1,L=function(t){if(k)k=!1,A();else{E.confirmTransitionTo(t,"POP",y,function(e){e?A({action:"POP",location:t}):P(t)})}},P=function(t){var e=D.location,n=x.indexOf(e.key);-1===n&&(n=0);var r=x.indexOf(t.key);-1===r&&(r=0);var o=n-r;o&&(k=!0,U(o))},_=b(f()),x=[_.key],S=function(t){return O+(0,h.createPath)(t)},T=function(t,o){(0,a.default)(!("object"===(void 0===t?"undefined":r(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to push when the 1st argument is a location-like object that already has state; it is ignored");var i=(0,l.createLocation)(t,o,w(),D.location);E.confirmTransitionTo(i,"PUSH",y,function(t){if(t){var r=S(i),o=i.key,u=i.state;if(n)if(e.pushState({key:o,state:u},null,r),d)window.location.href=r;else{var s=x.indexOf(D.location.key),c=x.slice(0,-1===s?0:s+1);c.push(i.key),x=c,A({action:"PUSH",location:i})}else(0,a.default)(void 0===u,"Browser history cannot push state in browsers that do not support HTML5 history"),window.location.href=r}})},C=function(t,o){(0,a.default)(!("object"===(void 0===t?"undefined":r(t))&&void 0!==t.state&&void 0!==o),"You should avoid providing a 2nd state argument to replace when the 1st argument is a location-like object that already has state; it is ignored");var i=(0,l.createLocation)(t,o,w(),D.location);E.confirmTransitionTo(i,"REPLACE",y,function(t){if(t){var r=S(i),o=i.key,u=i.state;if(n)if(e.replaceState({key:o,state:u},null,r),d)window.location.replace(r);else{var s=x.indexOf(D.location.key);-1!==s&&(x[s]=i.key),A({action:"REPLACE",location:i})}else(0,a.default)(void 0===u,"Browser history cannot replace state in browsers that do not support HTML5 history"),window.location.replace(r)}})},U=function(t){e.go(t)},M=function(){return U(-1)},H=function(){return U(1)},B=0,G=function(t){1===(B+=t)?((0,v.addEventListener)(window,"popstate",R),i&&(0,v.addEventListener)(window,"hashchange",j)):0===B&&((0,v.removeEventListener)(window,"popstate",R),i&&(0,v.removeEventListener)(window,"hashchange",j))},F=!1,N=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=E.setPrompt(t);return F||(G(1),F=!0),function(){return F&&(F=!1,G(-1)),e()}},I=function(t){var e=E.appendListener(t);return G(1),function(){G(-1),e()}},D={length:e.length,action:"POP",location:_,createHref:S,push:T,replace:C,go:U,goBack:M,goForward:H,block:N,listen:I};return D};e.default=d})),m=Object.getOwnPropertySymbols,g=Object.prototype.hasOwnProperty,O=Object.prototype.propertyIsEnumerable,b=function(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de","5"===Object.getOwnPropertyNames(t)[0])return!1;for(var e={},n=0;n<10;n++)e["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(e).map(function(t){return e[t]}).join(""))return!1;var r={};return"abcdefghijklmnopqrst".split("").forEach(function(t){r[t]=t}),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},r)).join("")}catch(t){return!1}}()?Object.assign:function(t,e){for(var r,o,a=n(t),i=1;i<arguments.length;i++){r=Object(arguments[i]);for(var u in r)g.call(r,u)&&(a[u]=r[u]);if(m){o=m(r);for(var s=0;s<o.length;s++)O.call(r,o[s])&&(a[o[s]]=r[o[s]])}}return a},w=function(t,e){var n=r(e=b({arrayFormat:"none"},e)),a=Object.create(null);return"string"!=typeof t?a:(t=t.trim().replace(/^(\?|#|&)/,""))?(t.split("&").forEach(function(t){var e=t.replace(/\+/g," ").split("="),r=e.shift(),o=e.length>0?e.join("="):void 0;o=void 0===o?null:decodeURIComponent(o),n(decodeURIComponent(r),o,a)}),Object.keys(a).sort().reduce(function(t,e){var n=a[e];return Boolean(n)&&"object"==typeof n&&!Array.isArray(n)?t[e]=o(n):t[e]=n,t},Object.create(null))):a},E="ROUTER/PUSH",A="ROUTER/REPLACE",R="ROUTER/GO",j="ROUTER/GO_BACK",k=function(t){return{type:E,payload:t}},L=function(t){return{type:A,payload:t}},P=function(t){return{type:R,payload:t}},_=function(){return{type:j}},x=function(){return{type:"ROUTER/GO_FORWARD"}},S=function(t){var e=t.pathname,n=t.search,r=t.hash;return{type:"ROUTER/LOCATION_CHANGE",payload:{pathname:e,search:n,queries:w(n),hash:r}}},T=function(t){return function(){return function(e){return function(n){switch(n.type){case E:t.push(n.payload);break;case A:t.replace(n.payload);break;case R:t.go(n.payload);break;case j:t.goBack();break;case"ROUTER/GO_FORWARD":t.goForward();break;default:return e(n)}}}}},C=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},U={pathname:"/",search:"",queries:{},hash:""},M=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:U,e=arguments[1];switch(e.type){case"ROUTER/LOCATION_CHANGE":return C({},t,e.payload);default:return t}};t.createBrowserHistory=y,t.startListener=a,t.PUSH=E,t.REPLACE=A,t.GO=R,t.GO_BACK=j,t.GO_FORWARD="ROUTER/GO_FORWARD",t.LOCATION_CHANGE="ROUTER/LOCATION_CHANGE",t.push=k,t.replace=L,t.go=P,t.goBack=_,t.goForward=x,t.locationChange=S,t.routerMiddleware=T,t.routerReducer=M,Object.defineProperty(t,"__esModule",{value:!0})});
{
"name": "redux-first-routing",
"version": "0.2.0",
"version": "0.2.1",
"description": "Redux-first routing",

@@ -35,3 +35,3 @@ "main": "lib/index.js",

"dependencies": {
"history": "^4.6.1",
"history": "^4.6.2",
"query-string": "^4.3.4"

@@ -41,3 +41,3 @@ },

"babel-cli": "^6.24.1",
"babel-core": "^6.24.1",
"babel-core": "^6.25.0",
"babel-eslint": "^7.2.3",

@@ -48,4 +48,4 @@ "babel-plugin-transform-object-rest-spread": "^6.23.0",

"chai": "^4.0.2",
"cross-env": "^5.0.0",
"eslint": "^3.19.0",
"cross-env": "^5.0.1",
"eslint": "^4.0.0",
"eslint-config-airbnb-base": "^11.2.0",

@@ -55,3 +55,3 @@ "eslint-plugin-import": "^2.2.0",

"rimraf": "^2.6.1",
"rollup": "^0.42.0",
"rollup": "^0.43.0",
"rollup-plugin-babel": "^2.7.1",

@@ -62,3 +62,3 @@ "rollup-plugin-commonjs": "^8.0.2",

"rollup-plugin-uglify": "^2.0.1",
"sinon": "^2.3.2"
"sinon": "^2.3.4"
},

@@ -65,0 +65,0 @@ "scripts": {

@@ -1,2 +0,2 @@

# Redux-First Routing [![npm version](https://img.shields.io/npm/v/redux-first-routing.svg?style=flat)](https://www.npmjs.org/package/redux-first-routing)
# Redux-First Routing [![npm version](https://img.shields.io/npm/v/redux-first-routing.svg?style=flat)](https://www.npmjs.org/package/redux-first-routing) [![build status](https://api.travis-ci.org/mksarge/redux-first-routing.svg?branch=master)](https://travis-ci.org/mksarge/redux-first-routing/)

@@ -15,7 +15,7 @@ Achieve client-side routing *the Redux way*:

Instead, you can pair it with a compatible client-side routing library from your framework of choice, to create a complete routing solution (see [Recipies](#recipies) for full examples).
Instead, you can pair it with a [compatible router](#compatible-routers) to create a complete routing solution. If you're coming from React Router, you might compare this package to [`react-router-redux`](https://github.com/reactjs/react-router-redux).
## Installation
Using [npm](https://www.npmjs.org/package/redux-first-routing):
Install the library from [npm](https://www.npmjs.org/package/redux-first-routing):

@@ -32,23 +32,59 @@ ```

## Recipies
## Usage
- [Basic Usage](https://github.com/mksarge/redux-first-routing/blob/master/docs/basic-usage.md)
- [Usage with Universal Router](https://github.com/mksarge/redux-first-routing/blob/master/docs/usage-with-universal-router.md)
#### Basic Usage
## API
```js
import { combineReducers, applyMiddleware, createStore } from 'redux'
import { createBrowserHistory, routerReducer, routerMiddleware, startListener, push } from 'redux-first-routing'
import { otherReducers } from './reducers'
// Create the history object
const history = createBrowserHistory()
// Add the reducer, which adds location state to the store
const rootReducer = combineReducers({
...otherReducers,
router: routerReducer // Convention is to use the "router" property
})
// Build the middleware, which intercepts navigation actions and calls the corresponding history method
const middleware = routerMiddleware(history)
// Create the store
const store = createStore(rootReducer, {}, applyMiddleware(middleware))
// Start the history listener, which automatically dispatches actions to keep the store in sync with the history
startListener(history, store)
// Now you can read the location from the store!
let currentLocation = store.getState().router.pathname
// You can also subscribe to changes in the location!
let unsubscribe = store.subscribe(() => {
let previousLocation = currentLocation
currentLocation = store.getState().router.pathname
if (previousLocation !== currentLocation) {
console.log(`Location changed from ${previousLocation} to ${currentLocation}`)
// Render your application reactively here (optionally using a compatible router)
}
})
// And you can dispatch navigation actions from anywhere!
store.dispatch(push('/about'))
```
#### State Shape
There are dozens of ways to design the state shape of the location data, and this project must by nature choose a single, opinonated design. Here is the current design:
There are dozens of ways to design the state shape of the location data, and this project must by nature choose an opinionated design:
```js
// window.location => www.example.com/nested/path?with=query#and-hash
// URL: www.example.com/nested/path?with=query#and-hash
{
..., // other redux state
location: {
router: {
pathname: '/nested/path/',
search: '?with=query',
queries: {
with: 'query',
with: 'query'
},

@@ -60,34 +96,21 @@ hash: '#and-hash'

#### Exports
> If the current design doesn't fit your needs, feel free to open an issue or fork the project.
Here's a look at the exports in [`src/index.js`](https://github.com/mksarge/redux-first-routing/blob/master/src/index.js):
#### Compatible Routers
```js
// History API
export { createBrowserHistory } from 'history/createBrowserHistory';
export { startListener } from './listener';
For a routing library to work seamlessly with `redux-first-routing`, **it must not be heavily coupled with the browser history**. For example, React Router [wraps its own instance of `history`](https://github.com/ReactTraining/react-router/blob/master/packages/react-router-dom/modules/BrowserRouter.js#L18-L21), so a more integrated solution like `react-router-redux` is necessary.
// Redux API
export { PUSH, REPLACE, GO, GO_BACK, GO_FORWARD, LOCATION_CHANGE } from './constants';
export { push, replace, go, goBack, goForward, locationChange } from './actions';
export { routerMiddleware } from './middleware';
export { routerReducer } from './reducer';
```
The following libraries provide router components that just focus on the *routing* and/or *rendering* part, making them great matches for `redux-first-routing`:
- **Redux API**
- `push()`, `replace()`, `go()`, `goBack()`, `goForward()`
- Public action creators used to update the location.
- **Use these navigation actions instead of calling the `history` navigation methods directly!**
- `PUSH`, `REPLACE`, `GO`, `GO_BACK`, `GO_FORWARD`
- Public action types for use in user-defined middleware.
- `routerMiddleware(history)`
- Intercepts the navigation actions to update the browser history.
- `routerReducer`
- Adds the location data (`pathname`, `search`, `hash`) to the state tree upon receiving a `LOCATION_CHANGE` action.
- **History API**
- `createBrowserHistory()`
- Creates a `history` object.
- `startListener(history, store)`
- Creates a `history` [listener](https://github.com/ReactTraining/history#listening) that responds to the middleware and external navigation by dispatching a `locationChange` action.
- [Universal Router](https://github.com/kriasoft/universal-router) (framework-agnostic)
- [Redux JSON Router](https://github.com/mksarge/redux-json-router) (React)
> For full examples of usage, see [Recipies](#documentation). To add to this list, feel free to send a pull request.
## Documentation
- [API](/docs/api.md)
- Recipies
- [Usage with Universal Router](/docs/recipes/usage-with-universal-router.md)
## Contributing

@@ -94,0 +117,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc