From 2cf8d70c0f01734dd761030d3573eba8a4d3824a Mon Sep 17 00:00:00 2001 From: April Mintac Pinedam Date: Sun, 24 Jun 2018 15:54:54 +0800 Subject: [PATCH] always clear saved store when mounting; used persist in demo; updated docs; --- README.md | 45 ++++++++- __tests__/connect.spec.js | 12 ++- __tests__/provider-persist.spec.js | 39 +++++++- example/build/app.js | 22 +++++ example/build/index.html | 13 +++ example/package-lock.json | 6 +- example/package.json | 6 +- example/src/entry.js | 11 ++- example/src/lib.js | 149 +++++++++++++++++++++++++++++ example/src/routes/Home.js | 3 +- example/src/routes/Todos.js | 2 +- lib/index.js | 8 +- package.json | 2 +- src/index.js | 11 +-- 14 files changed, 293 insertions(+), 36 deletions(-) create mode 100644 example/build/app.js create mode 100644 example/build/index.html create mode 100644 example/src/lib.js diff --git a/README.md b/README.md index 6124996..9d2a916 100644 --- a/README.md +++ b/README.md @@ -2,13 +2,10 @@ This library is actively being maintained by the developer. Feature requests, enhancements, and bug reports are all welcome to the issue section. # react-context-api-store -Seemless, lightweight, state management library that comes with asynchronous support out of the box. Inspired by Redux and Vuex. Built on top of [React's context api](https://reactjs.org/docs/context.html). +Seemless, lightweight, state management library that supports async actions and state persisting out of the box. Inspired by Redux and Vuex. Built on top of [React's context api](https://reactjs.org/docs/context.html). # File size? -5kb transpiled, not minified. - -# Use case -When you want a state management that's small and supports asynchronous actions out of the box. +6.7kb transpiled. Not minified. Not compressed. Not uglified. # Example https://aprilmintacpineda.github.io/react-context-api-store/#/ @@ -286,6 +283,44 @@ function myStateHandler (store, data) { } ``` +## Persisting states + +If you want to persist states, just provide a second property called `persist` which is an object that has the following shape: + +```js +{ + storage: AsyncStorage, // the storage of where to save the state + statesToPersist: savedStore => { + // do whatever you need to do here + // then return the states that you want to save. + // NOTE: This is not strict, meaning, you can even + // create a new state here and it will still be saved + return { + someState: { ...savedStore.someState }, + anotherState: [ ...savedStore.anotherState ], + someValue: savedStore.someValue + } + } +} +``` + +**example snippet** + +```jsx + +``` + +In this case I'm passing in the `window.localStorage` as the storage but you are free to use whatever storage you need but it must have the following methods: + +- `getItem` which receives the `key` as the first parameter. +- `setItem` which receives the `key` as the first parameter and `value` as the second parameter. +- `removeItem` which receives the `key` as the first parameter. + # Related - [inferno-context-api-store](https://github.com/aprilmintacpineda/inferno-context-api-store) inferno compatible version of the same thing. \ No newline at end of file diff --git a/__tests__/connect.spec.js b/__tests__/connect.spec.js index 307b45f..a84f634 100644 --- a/__tests__/connect.spec.js +++ b/__tests__/connect.spec.js @@ -7,7 +7,8 @@ test('passes states as props to connected components', () => { const persist = { storage: { getItem: jest.fn(), - setItem: jest.fn() + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: () => ({}) }; @@ -46,7 +47,8 @@ test('calls persist.storage.setItem with default key when an action was dispatch const persist = { storage: { getItem: jest.fn(), - setItem: jest.fn() + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: () => ({}) }; @@ -117,7 +119,8 @@ test('calls persist.storage.setItem with custom key when an action was dispatche const persist = { storage: { getItem: jest.fn(), - setItem: jest.fn() + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: () => ({}), key: 'my-custom-key' @@ -189,7 +192,8 @@ test('does not call persist.storage.setItem action was dispatched an persist pro const persist = { storage: { getItem: jest.fn(), - setItem: jest.fn() + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: () => ({}) }; diff --git a/__tests__/provider-persist.spec.js b/__tests__/provider-persist.spec.js index 0f9e7f3..0d9b009 100644 --- a/__tests__/provider-persist.spec.js +++ b/__tests__/provider-persist.spec.js @@ -19,7 +19,9 @@ const persistedStates = { }; const mockedStorage = { - getItem: () => JSON.stringify(persistedStates) + getItem: () => JSON.stringify(persistedStates), + setItem: jest.fn(), + removeItem: jest.fn() }; test('matches snapshot when persist was provided', () => { @@ -42,14 +44,27 @@ test('matches snapshot when persist was provided', () => { ).toMatchSnapshot(); }); -test('calls persist.storage.getItem when persist prop was provided', () => { +test('calls persist.storage.getItem and persist.storage.removeItem when persist prop was provided', () => { const persist = { storage: { - getItem: jest.fn() + getItem: jest.fn(), + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: jest.fn() }; + expect(renderer.create( + +
+

This is the app

+
+
+ ).getInstance().props.persist.storage.removeItem).toHaveBeenCalledWith('react-context-api-store'); + expect(renderer.create( { ).getInstance().props.persist.storage.getItem).toHaveBeenCalledWith('my-app-custom-key'); + + expect(renderer.create( + +
+

This is the app

+
+
+ ).getInstance().props.persist.storage.removeItem).toHaveBeenCalledWith('my-app-custom-key'); }); test('does not call persist.statesToPersist when store.getItem returned null', () => { const persist = { storage: { - getItem: () => null + getItem: () => null, + setItem: jest.fn(), + removeItem: jest.fn() }, statesToPersist: jest.fn() }; diff --git a/example/build/app.js b/example/build/app.js new file mode 100644 index 0000000..94c7cff --- /dev/null +++ b/example/build/app.js @@ -0,0 +1,22 @@ +!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=29)}([function(e,t,n){e.exports=n(19)()},function(e,t,n){"use strict";e.exports=n(28)},function(e,t,n){"use strict";var r=function(){};e.exports=r},function(e,t,n){"use strict";e.exports=function(e,t,n,r,o,a,i,u){if(!e){var l;if(void 0===t)l=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],s=0;(l=new Error(t.replace(/%s/g,function(){return c[s++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}}},function(e,t,n){"use strict";e.exports=function(){}},function(e,t,n){var r=n(17);e.exports=h,e.exports.parse=a,e.exports.compile=function(e,t){return l(a(e,t))},e.exports.tokensToFunction=l,e.exports.tokensToRegExp=d;var o=new RegExp(["(\\\\.)","([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))"].join("|"),"g");function a(e,t){for(var n,r=[],a=0,i=0,u="",l=t&&t.delimiter||"/";null!=(n=o.exec(e));){var f=n[0],p=n[1],d=n.index;if(u+=e.slice(i,d),i=d+f.length,p)u+=p[1];else{var h=e[i],m=n[2],y=n[3],v=n[4],g=n[5],b=n[6],w=n[7];u&&(r.push(u),u="");var x=null!=m&&null!=h&&h!==m,k="+"===b||"*"===b,E="?"===b||"*"===b,T=n[2]||l,_=v||g;r.push({name:y||a++,prefix:m||"",delimiter:T,optional:E,repeat:k,partial:x,asterisk:!!w,pattern:_?s(_):w?".*":"[^"+c(T)+"]+?"})}}return i1&&void 0!==arguments[1]?arguments[1]:"",n=e&&e.split("/")||[],r=t&&t.split("/")||[],o=e&&d(e),a=t&&d(t),i=o||a;if(e&&d(e)?r=n:n.length&&(r.pop(),r=r.concat(n)),!r.length)return"/";var u=void 0;if(r.length){var l=r[r.length-1];u="."===l||".."===l||""===l}else u=!1;for(var c=0,s=r.length;s>=0;s--){var f=r[s];"."===f?h(r,s):".."===f?(h(r,s),c++):c&&(h(r,s),c--)}if(!i)for(;c--;c)r.unshift("..");!i||""===r[0]||r[0]&&d(r[0])||r.unshift("");var p=r.join("/");return u&&"/"!==p.substr(-1)&&(p+="/"),p},y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};var v=function e(t,n){if(t===n)return!0;if(null==t||null==n)return!1;if(Array.isArray(t))return Array.isArray(n)&&t.length===n.length&&t.every(function(t,r){return e(t,n[r])});var r=void 0===t?"undefined":y(t);if(r!==(void 0===n?"undefined":y(n)))return!1;if("object"===r){var o=t.valueOf(),a=n.valueOf();if(o!==t||a!==n)return e(o,a);var i=Object.keys(t),u=Object.keys(n);return i.length===u.length&&i.every(function(r){return e(t[r],n[r])})}return!1},g=function(e){return"/"===e.charAt(0)?e:"/"+e},b=function(e){return"/"===e.charAt(0)?e.substr(1):e},w=function(e,t){return new RegExp("^"+t+"(\\/|\\?|#|$)","i").test(e)},x=function(e,t){return w(e,t)?e.substr(t.length):e},k=function(e){return"/"===e.charAt(e.length-1)?e.slice(0,-1):e},E=function(e){var t=e.pathname,n=e.search,r=e.hash,o=t||"/";return n&&"?"!==n&&(o+="?"===n.charAt(0)?n:"?"+n),r&&"#"!==r&&(o+="#"===r.charAt(0)?r:"#"+r),o},T=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{};p()(P,"Browser history needs a DOM");var t=window.history,n=function(){var e=window.navigator.userAgent;return(-1===e.indexOf("Android 2.")&&-1===e.indexOf("Android 4.0")||-1===e.indexOf("Mobile Safari")||-1!==e.indexOf("Chrome")||-1!==e.indexOf("Windows Phone"))&&window.history&&"pushState"in window.history}(),r=!(-1===window.navigator.userAgent.indexOf("Trident")),o=e.forceRefresh,a=void 0!==o&&o,i=e.getUserConfirmation,u=void 0===i?j:i,l=e.keyLength,c=void 0===l?6:l,f=e.basename?k(g(e.basename)):"",d=function(e){var t=e||{},n=t.key,r=t.state,o=window.location,a=o.pathname+o.search+o.hash;return s()(!f||w(a,f),'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "'+a+'" to begin with "'+f+'".'),f&&(a=x(a,f)),_(a,r,n)},h=function(){return Math.random().toString(36).substr(2,c)},m=S(),y=function(e){M(W,e),W.length=t.length,m.notifyListeners(W.location,W.action)},v=function(e){(function(e){return void 0===e.state&&-1===navigator.userAgent.indexOf("CriOS")})(e)||C(d(e.state))},b=function(){C(d(U()))},T=!1,C=function(e){T?(T=!1,y()):m.confirmTransitionTo(e,"POP",u,function(t){t?y({action:"POP",location:e}):A(e)})},A=function(e){var t=W.location,n=F.indexOf(t.key);-1===n&&(n=0);var r=F.indexOf(e.key);-1===r&&(r=0);var o=n-r;o&&(T=!0,L(o))},I=d(U()),F=[I.key],D=function(e){return f+E(e)},L=function(e){t.go(e)},z=0,B=function(e){1===(z+=e)?(O(window,"popstate",v),r&&O(window,"hashchange",b)):0===z&&(R(window,"popstate",v),r&&R(window,"hashchange",b))},H=!1,W={length:t.length,action:"POP",location:I,createHref:D,push:function(e,r){s()(!("object"===(void 0===e?"undefined":N(e))&&void 0!==e.state&&void 0!==r),"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 o=_(e,r,h(),W.location);m.confirmTransitionTo(o,"PUSH",u,function(e){if(e){var r=D(o),i=o.key,u=o.state;if(n)if(t.pushState({key:i,state:u},null,r),a)window.location.href=r;else{var l=F.indexOf(W.location.key),c=F.slice(0,-1===l?0:l+1);c.push(o.key),F=c,y({action:"PUSH",location:o})}else s()(void 0===u,"Browser history cannot push state in browsers that do not support HTML5 history"),window.location.href=r}})},replace:function(e,r){s()(!("object"===(void 0===e?"undefined":N(e))&&void 0!==e.state&&void 0!==r),"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 o=_(e,r,h(),W.location);m.confirmTransitionTo(o,"REPLACE",u,function(e){if(e){var r=D(o),i=o.key,u=o.state;if(n)if(t.replaceState({key:i,state:u},null,r),a)window.location.replace(r);else{var l=F.indexOf(W.location.key);-1!==l&&(F[l]=o.key),y({action:"REPLACE",location:o})}else s()(void 0===u,"Browser history cannot replace state in browsers that do not support HTML5 history"),window.location.replace(r)}})},go:L,goBack:function(){return L(-1)},goForward:function(){return L(1)},block:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=m.setPrompt(e);return H||(B(1),H=!0),function(){return H&&(H=!1,B(-1)),t()}},listen:function(e){var t=m.appendListener(e);return B(1),function(){B(-1),t()}}};return W},I=Object.assign||function(e){for(var t=1;t=0?t:0)+"#"+e)},z=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};p()(P,"Hash history needs a DOM");var t=window.history,n=-1===window.navigator.userAgent.indexOf("Firefox"),r=e.getUserConfirmation,o=void 0===r?j:r,a=e.hashType,i=void 0===a?"slash":a,u=e.basename?k(g(e.basename)):"",l=F[i],c=l.encodePath,f=l.decodePath,d=function(){var e=f(D());return s()(!u||w(e,u),'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "'+e+'" to begin with "'+u+'".'),u&&(e=x(e,u)),_(e)},h=S(),m=function(e){I(q,e),q.length=t.length,h.notifyListeners(q.location,q.action)},y=!1,v=null,b=function(){var e=D(),t=c(e);if(e!==t)L(t);else{var n=d(),r=q.location;if(!y&&C(r,n))return;if(v===E(n))return;v=null,T(n)}},T=function(e){y?(y=!1,m()):h.confirmTransitionTo(e,"POP",o,function(t){t?m({action:"POP",location:e}):N(e)})},N=function(e){var t=q.location,n=z.lastIndexOf(E(t));-1===n&&(n=0);var r=z.lastIndexOf(E(e));-1===r&&(r=0);var o=n-r;o&&(y=!0,B(o))},M=D(),U=c(M);M!==U&&L(U);var A=d(),z=[E(A)],B=function(e){s()(n,"Hash history go(n) causes a full page reload in this browser"),t.go(e)},H=0,W=function(e){1===(H+=e)?O(window,"hashchange",b):0===H&&R(window,"hashchange",b)},V=!1,q={length:t.length,action:"POP",location:A,createHref:function(e){return"#"+c(u+E(e))},push:function(e,t){s()(void 0===t,"Hash history cannot push state; it is ignored");var n=_(e,void 0,void 0,q.location);h.confirmTransitionTo(n,"PUSH",o,function(e){if(e){var t=E(n),r=c(u+t);if(D()!==r){v=t,function(e){window.location.hash=e}(r);var o=z.lastIndexOf(E(q.location)),a=z.slice(0,-1===o?0:o+1);a.push(t),z=a,m({action:"PUSH",location:n})}else s()(!1,"Hash history cannot PUSH the same path; a new entry will not be added to the history stack"),m()}})},replace:function(e,t){s()(void 0===t,"Hash history cannot replace state; it is ignored");var n=_(e,void 0,void 0,q.location);h.confirmTransitionTo(n,"REPLACE",o,function(e){if(e){var t=E(n),r=c(u+t);D()!==r&&(v=t,L(r));var o=z.indexOf(E(q.location));-1!==o&&(z[o]=t),m({action:"REPLACE",location:n})}})},go:B,goBack:function(){return B(-1)},goForward:function(){return B(1)},block:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=h.setPrompt(e);return V||(W(1),V=!0),function(){return V&&(V=!1,W(-1)),t()}},listen:function(e){var t=h.appendListener(e);return W(1),function(){W(-1),t()}}};return q},B="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},H=Object.assign||function(e){for(var t=1;t0&&void 0!==arguments[0]?arguments[0]:{},t=e.getUserConfirmation,n=e.initialEntries,r=void 0===n?["/"]:n,o=e.initialIndex,a=void 0===o?0:o,i=e.keyLength,u=void 0===i?6:i,l=S(),c=function(e){H(y,e),y.length=y.entries.length,l.notifyListeners(y.location,y.action)},f=function(){return Math.random().toString(36).substr(2,u)},p=W(a,0,r.length-1),d=r.map(function(e){return _(e,void 0,"string"==typeof e?f():e.key||f())}),h=E,m=function(e){var n=W(y.index+e,0,y.entries.length-1),r=y.entries[n];l.confirmTransitionTo(r,"POP",t,function(e){e?c({action:"POP",location:r,index:n}):c()})},y={length:d.length,action:"POP",location:d[p],index:p,entries:d,createHref:h,push:function(e,n){s()(!("object"===(void 0===e?"undefined":B(e))&&void 0!==e.state&&void 0!==n),"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 r=_(e,n,f(),y.location);l.confirmTransitionTo(r,"PUSH",t,function(e){if(e){var t=y.index+1,n=y.entries.slice(0);n.length>t?n.splice(t,n.length-t,r):n.push(r),c({action:"PUSH",location:r,index:t,entries:n})}})},replace:function(e,n){s()(!("object"===(void 0===e?"undefined":B(e))&&void 0!==e.state&&void 0!==n),"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 r=_(e,n,f(),y.location);l.confirmTransitionTo(r,"REPLACE",t,function(e){e&&(y.entries[y.index]=r,c({action:"REPLACE",location:r}))})},go:m,goBack:function(){return m(-1)},goForward:function(){return m(1)},canGo:function(e){var t=y.index+e;return t>=0&&t0&&void 0!==arguments[0]&&arguments[0];return l.setPrompt(e)},listen:function(e){return l.appendListener(e)}};return y},q=Object.assign||function(e){for(var t=1;t may have only one child element"),this.unlisten=r.listen(function(){e.setState({match:e.computeMatch(r.location.pathname)})})},t.prototype.componentWillReceiveProps=function(e){o()(this.props.history===e.history,"You cannot change ")},t.prototype.componentWillUnmount=function(){this.unlisten()},t.prototype.render=function(){var e=this.props.children;return e?i.a.Children.only(e):null},t}(i.a.Component);Y.propTypes={history:l.a.object.isRequired,children:l.a.node},Y.contextTypes={router:l.a.object},Y.childContextTypes={router:l.a.object.isRequired};var K=Y,Q=K;function G(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var X=function(e){function t(){var n,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,a=Array(o),i=0;i ignores the history prop. To use a custom history, use `import { Router }` instead of `import { BrowserRouter as Router }`.")},t.prototype.render=function(){return i.a.createElement(Q,{history:this.history,children:this.props.children})},t}(i.a.Component);X.propTypes={basename:l.a.string,forceRefresh:l.a.bool,getUserConfirmation:l.a.func,keyLength:l.a.number,children:l.a.node};var J=X;function Z(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var ee=function(e){function t(){var n,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,a=Array(o),i=0;i ignores the history prop. To use a custom history, use `import { Router }` instead of `import { HashRouter as Router }`.")},t.prototype.render=function(){return i.a.createElement(Q,{history:this.history,children:this.props.children})},t}(i.a.Component);ee.propTypes={basename:l.a.string,getUserConfirmation:l.a.func,hashType:l.a.oneOf(["hashbang","noslash","slash"]),children:l.a.node};var te=ee,ne=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(e,["replace","to","innerRef"]);p()(this.context.router,"You should not use outside a "),p()(void 0!==t,'You must specify the "to" property');var o=this.context.router.history,a="string"==typeof t?_(t,null,null,o.location):t,u=o.createHref(a);return i.a.createElement("a",ne({},r,{onClick:this.handleClick,href:u,ref:n}))},t}(i.a.Component);ae.propTypes={onClick:l.a.func,target:l.a.string,replace:l.a.bool,to:l.a.oneOfType([l.a.string,l.a.object]).isRequired,innerRef:l.a.oneOfType([l.a.string,l.a.func])},ae.defaultProps={replace:!1},ae.contextTypes={router:l.a.shape({history:l.a.shape({push:l.a.func.isRequired,replace:l.a.func.isRequired,createHref:l.a.func.isRequired}).isRequired}).isRequired};var ie=ae;function ue(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}var le=function(e){function t(){var n,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,a=Array(o),i=0;i ignores the history prop. To use a custom history, use `import { Router }` instead of `import { MemoryRouter as Router }`.")},t.prototype.render=function(){return i.a.createElement(K,{history:this.history,children:this.props.children})},t}(i.a.Component);le.propTypes={initialEntries:l.a.array,initialIndex:l.a.number,getUserConfirmation:l.a.func,keyLength:l.a.number,children:l.a.node};var ce=le,se=n(5),fe=n.n(se),pe={},de=0,he=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments[2];"string"==typeof t&&(t={path:t});var r=t,o=r.path,a=r.exact,i=void 0!==a&&a,u=r.strict,l=void 0!==u&&u,c=r.sensitive,s=void 0!==c&&c;if(null==o)return n;var f=function(e,t){var n=""+t.end+t.strict+t.sensitive,r=pe[n]||(pe[n]={});if(r[e])return r[e];var o=[],a={re:fe()(e,o,t),keys:o};return de<1e4&&(r[e]=a,de++),a}(o,{end:i,strict:l,sensitive:s}),p=f.re,d=f.keys,h=p.exec(e);if(!h)return null;var m=h[0],y=h.slice(1),v=e===m;return i&&!v?null:{path:o,url:"/"===o&&""===m?"/":m,isExact:v,params:d.reduce(function(e,t,n){return e[t.name]=y[n],e},{})}},me=Object.assign||function(e){for(var t=1;t or withRouter() outside a ");var l=t.route,c=(r||l.location).pathname;return he(c,{path:o,strict:a,exact:i,sensitive:u},l.match)},t.prototype.componentWillMount=function(){o()(!(this.props.component&&this.props.render),"You should not use and in the same route; will be ignored"),o()(!(this.props.component&&this.props.children&&!ve(this.props.children)),"You should not use and in the same route; will be ignored"),o()(!(this.props.render&&this.props.children&&!ve(this.props.children)),"You should not use and in the same route; will be ignored")},t.prototype.componentWillReceiveProps=function(e,t){o()(!(e.location&&!this.props.location),' elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'),o()(!(!e.location&&this.props.location),' elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.'),this.setState({match:this.computeMatch(e,t.router)})},t.prototype.render=function(){var e=this.state.match,t=this.props,n=t.children,r=t.component,o=t.render,a=this.context.router,u=a.history,l=a.route,c=a.staticContext,s={match:e,location:this.props.location||l.location,history:u,staticContext:c};return r?e?i.a.createElement(r,s):null:o?e?o(s):null:"function"==typeof n?n(s):n&&!ve(n)?i.a.Children.only(n):null},t}(i.a.Component);ge.propTypes={computedMatch:l.a.object,path:l.a.string,exact:l.a.bool,strict:l.a.bool,sensitive:l.a.bool,component:l.a.func,render:l.a.func,children:l.a.oneOfType([l.a.func,l.a.node]),location:l.a.object},ge.contextTypes={router:l.a.shape({history:l.a.object.isRequired,route:l.a.object.isRequired,staticContext:l.a.object})},ge.childContextTypes={router:l.a.object.isRequired};var be=ge,we=be,xe=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(e,["to","exact","strict","location","activeClassName","className","activeStyle","style","isActive","aria-current"]),d="object"===(void 0===t?"undefined":ke(t))?t.pathname:t,h=d&&d.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1");return i.a.createElement(we,{path:h,exact:n,strict:r,location:o,children:function(e){var n=e.location,r=e.match,o=!!(s?s(r,n):r);return i.a.createElement(ie,xe({to:t,className:o?[u,a].filter(function(e){return e}).join(" "):u,style:o?xe({},c,l):c,"aria-current":o&&f||null},p))}})};Ee.propTypes={to:ie.propTypes.to,exact:l.a.bool,strict:l.a.bool,location:l.a.object,activeClassName:l.a.string,className:l.a.string,activeStyle:l.a.object,style:l.a.object,isActive:l.a.func,"aria-current":l.a.oneOf(["page","step","location","date","time","true"])},Ee.defaultProps={activeClassName:"active","aria-current":"page"};var Te=Ee;var _e=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.enable=function(e){this.unblock&&this.unblock(),this.unblock=this.context.router.history.block(e)},t.prototype.disable=function(){this.unblock&&(this.unblock(),this.unblock=null)},t.prototype.componentWillMount=function(){p()(this.context.router,"You should not use outside a "),this.props.when&&this.enable(this.props.message)},t.prototype.componentWillReceiveProps=function(e){e.when?this.props.when&&this.props.message===e.message||this.enable(e.message):this.disable()},t.prototype.componentWillUnmount=function(){this.disable()},t.prototype.render=function(){return null},t}(i.a.Component);_e.propTypes={when:l.a.bool,message:l.a.oneOfType([l.a.func,l.a.string]).isRequired},_e.defaultProps={when:!0},_e.contextTypes={router:l.a.shape({history:l.a.shape({block:l.a.func.isRequired}).isRequired}).isRequired};var Ce=_e,Se={},Pe=0,Oe=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return"/"===e?e:function(e){var t=e,n=Se[t]||(Se[t]={});if(n[e])return n[e];var r=fe.a.compile(e);return Pe<1e4&&(n[e]=r,Pe++),r}(e)(t,{pretty:!0})},Re=Object.assign||function(e){for(var t=1;t outside a "),this.isStatic()&&this.perform()},t.prototype.componentDidMount=function(){this.isStatic()||this.perform()},t.prototype.componentDidUpdate=function(e){var t=_(e.to),n=_(this.props.to);C(t,n)?o()(!1,"You tried to redirect to the same route you're currently on: \""+n.pathname+n.search+'"'):this.perform()},t.prototype.computeTo=function(e){var t=e.computedMatch,n=e.to;return t?"string"==typeof n?Oe(n,t.params):Re({},n,{pathname:Oe(n.pathname,t.params)}):n},t.prototype.perform=function(){var e=this.context.router.history,t=this.props.push,n=this.computeTo(this.props);t?e.push(n):e.replace(n)},t.prototype.render=function(){return null},t}(i.a.Component);je.propTypes={computedMatch:l.a.object,push:l.a.bool,from:l.a.string,to:l.a.oneOfType([l.a.string,l.a.object]).isRequired},je.defaultProps={push:!1},je.contextTypes={router:l.a.shape({history:l.a.shape({push:l.a.func.isRequired,replace:l.a.func.isRequired}).isRequired,staticContext:l.a.object}).isRequired};var Ne=je,Me=Object.assign||function(e){for(var t=1;t",e)}},Le=function(){},ze=function(e){function t(){var n,r;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);for(var o=arguments.length,a=Array(o),i=0;i ignores the history prop. To use a custom history, use `import { Router }` instead of `import { StaticRouter as Router }`.")},t.prototype.render=function(){var e=this.props,t=e.basename,n=(e.context,e.location),r=function(e,t){var n={};for(var r in e)t.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(e,["basename","context","location"]),o={createHref:this.createHref,action:"POP",location:function(e,t){if(!e)return t;var n=Ae(e);return 0!==t.pathname.indexOf(n)?t:Me({},t,{pathname:t.pathname.substr(n.length)})}(t,_(n)),push:this.handlePush,replace:this.handleReplace,go:De("go"),goBack:De("goBack"),goForward:De("goForward"),listen:this.handleListen,block:this.handleBlock};return i.a.createElement(K,Me({},r,{history:o}))},t}(i.a.Component);ze.propTypes={basename:l.a.string,context:l.a.object.isRequired,location:l.a.oneOfType([l.a.string,l.a.object])},ze.defaultProps={basename:"",location:"/"},ze.childContextTypes={router:l.a.object.isRequired};var Be=ze;var He=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.apply(this,arguments))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.componentWillMount=function(){p()(this.context.router,"You should not use outside a ")},t.prototype.componentWillReceiveProps=function(e){o()(!(e.location&&!this.props.location),' elements should not change from uncontrolled to controlled (or vice versa). You initially used no "location" prop and then provided one on a subsequent render.'),o()(!(!e.location&&this.props.location),' elements should not change from controlled to uncontrolled (or vice versa). You provided a "location" prop initially but omitted it on a subsequent render.')},t.prototype.render=function(){var e=this.context.router.route,t=this.props.children,n=this.props.location||e.location,r=void 0,o=void 0;return i.a.Children.forEach(t,function(t){if(null==r&&i.a.isValidElement(t)){var a=t.props,u=a.path,l=a.exact,c=a.strict,s=a.sensitive,f=a.from,p=u||f;o=t,r=he(n.pathname,{path:p,exact:l,strict:c,sensitive:s},e.match)}}),r?i.a.cloneElement(o,{location:n,computedMatch:r}):null},t}(i.a.Component);He.contextTypes={router:l.a.shape({route:l.a.object.isRequired}).isRequired},He.propTypes={children:l.a.node,location:l.a.object};var We=He,Ve=Oe,qe=he,$e=n(12),Ye=n.n($e),Ke=Object.assign||function(e){for(var t=1;t=0||Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=e[r]);return n}(t,["wrappedComponentRef"]);return i.a.createElement(be,{children:function(t){return i.a.createElement(e,Ke({},r,t,{ref:n}))}})};return t.displayName="withRouter("+(e.displayName||e.name)+")",t.WrappedComponent=e,t.propTypes={wrappedComponentRef:l.a.func},Ye()(t,e)};n.d(t,"BrowserRouter",function(){return J}),n.d(t,"HashRouter",function(){return te}),n.d(t,"Link",function(){return ie}),n.d(t,"MemoryRouter",function(){return ce}),n.d(t,"NavLink",function(){return Te}),n.d(t,"Prompt",function(){return Ce}),n.d(t,"Redirect",function(){return Ne}),n.d(t,"Route",function(){return we}),n.d(t,"Router",function(){return Q}),n.d(t,"StaticRouter",function(){return Be}),n.d(t,"Switch",function(){return We}),n.d(t,"generatePath",function(){return Ve}),n.d(t,"matchPath",function(){return qe}),n.d(t,"withRouter",function(){return Qe})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=function(){function e(e,t){for(var n=0;nthis.eventPool.length&&this.eventPool.push(e)}function Ee(e){e.eventPool=[],e.getPooled=xe,e.release=ke}i(we.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():"unknown"!=typeof e.returnValue&&(e.returnValue=!1),this.isDefaultPrevented=u.thatReturnsTrue)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():"unknown"!=typeof e.cancelBubble&&(e.cancelBubble=!0),this.isPropagationStopped=u.thatReturnsTrue)},persist:function(){this.isPersistent=u.thatReturnsTrue},isPersistent:u.thatReturnsFalse,destructor:function(){var e,t=this.constructor.Interface;for(e in t)this[e]=null;for(t=0;t=Pe),je=String.fromCharCode(32),Ne={beforeInput:{phasedRegistrationNames:{bubbled:"onBeforeInput",captured:"onBeforeInputCapture"},dependencies:["compositionend","keypress","textInput","paste"]},compositionEnd:{phasedRegistrationNames:{bubbled:"onCompositionEnd",captured:"onCompositionEndCapture"},dependencies:"blur compositionend keydown keypress keyup mousedown".split(" ")},compositionStart:{phasedRegistrationNames:{bubbled:"onCompositionStart",captured:"onCompositionStartCapture"},dependencies:"blur compositionstart keydown keypress keyup mousedown".split(" ")},compositionUpdate:{phasedRegistrationNames:{bubbled:"onCompositionUpdate",captured:"onCompositionUpdateCapture"},dependencies:"blur compositionupdate keydown keypress keyup mousedown".split(" ")}},Me=!1;function Ue(e,t){switch(e){case"keyup":return-1!==Ce.indexOf(t.keyCode);case"keydown":return 229!==t.keyCode;case"keypress":case"mousedown":case"blur":return!0;default:return!1}}function Ae(e){return"object"==typeof(e=e.detail)&&"data"in e?e.data:null}var Ie=!1;var Fe={eventTypes:Ne,extractEvents:function(e,t,n,r){var o=void 0,a=void 0;if(Se)e:{switch(e){case"compositionstart":o=Ne.compositionStart;break e;case"compositionend":o=Ne.compositionEnd;break e;case"compositionupdate":o=Ne.compositionUpdate;break e}o=void 0}else Ie?Ue(e,n)&&(o=Ne.compositionEnd):"keydown"===e&&229===n.keyCode&&(o=Ne.compositionStart);return o?(Re&&(Ie||o!==Ne.compositionStart?o===Ne.compositionEnd&&Ie&&(a=ye()):(me._root=r,me._startText=ve(),Ie=!0)),o=Te.getPooled(o,t,n,r),a?o.data=a:null!==(a=Ae(n))&&(o.data=a),ee(o),a=o):a=null,(e=Oe?function(e,t){switch(e){case"compositionend":return Ae(t);case"keypress":return 32!==t.which?null:(Me=!0,je);case"textInput":return(e=t.data)===je&&Me?null:e;default:return null}}(e,n):function(e,t){if(Ie)return"compositionend"===e||!Se&&Ue(e,t)?(e=ye(),me._root=null,me._startText=null,me._fallbackText=null,Ie=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1