react-causality-redux
Version:
Causality based extension of react-redux
22 lines (21 loc) • 9.45 kB
JavaScript
/*
? 2017 Andrew Banks ALL RIGHTS RESERVED */
(function(r){function l(c){if(f[c])return f[c].exports;var e=f[c]={i:c,l:!1,exports:{}};r[c].call(e.exports,e,e.exports,l);e.l=!0;return e.exports}var f={};l.m=r;l.c=f;l.i=function(c){return c};l.d=function(c,e,p){l.o(c,e)||Object.defineProperty(c,e,{configurable:!1,enumerable:!0,get:p})};l.n=function(c){var e=c&&c.__esModule?function(){return c["default"]}:function(){return c};l.d(e,"a",e);return e};l.o=function(c,e){return Object.prototype.hasOwnProperty.call(c,e)};l.p="";return l(l.s=0)})([function(r,
l){(function(f){function c(p){if(e[p])return e[p].exports;var n=e[p]={i:p,l:!1,exports:{}};f[p].call(n.exports,n,n.exports,c);n.l=!0;return n.exports}var e={};c.m=f;c.c=e;c.i=function(c){return c};c.d=function(e,n,f){c.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:f})};c.n=function(e){var f=e&&e.__esModule?function(){return e["default"]}:function(){return e};c.d(f,"a",f);return f};c.o=function(c,e){return Object.prototype.hasOwnProperty.call(c,e)};c.p="";return c(c.s=2)})([function(f,
c){f.exports=CausalityRedux},function(f,c){f.exports=ReactRedux},function(f,c,e){function l(d,a){if("function"!==typeof a&&null!==a)throw new TypeError("Super expression must either be null or a function, not "+typeof a);d.prototype=Object.create(a&&a.prototype,{constructor:{value:d,enumerable:!1,writable:!0,configurable:!0}});a&&(Object.setPrototypeOf?Object.setPrototypeOf(d,a):d.__proto__=a)}function n(d){if(Array.isArray(d)){for(var a=0,b=Array(d.length);a<d.length;a++)b[a]=d[a];return b}return Array.from(d)}
function r(d){return function(){var a={};d.forEach(function(b){var d=g.default.store[b.partitionName];("undefined"===typeof d?"undefined":k(d))!==h&&b.changerKeys.forEach(function(b){a[b]=d[b]})});return a}}function F(d){var a=!1;d.forEach(function(b){a=a||k(b.changerKeys)!==h;g.default.partitionDefinitions.find(function(a){return b.partitionName===a.partitionName})||q(b.partitionName+" is not a valid state partition.");k(b.changerKeys)!==h&&b.changerKeys.forEach(function(a){"function"!==typeof g.default.store[b.partitionName][a]&&
q("The entry "+a+" is not a function.")})});if(a)return r(G(d))}function H(d){var a=[];d.forEach(function(b){if(k(b.storeKeys)!==h){var d=0!==b.storeKeys.length?[].concat(n(b.storeKeys)):g.default.getKeys(g.default.defaultState[b.partitionName]);a.push({partitionName:b.partitionName,storeKeys:d})}});return a}function I(d){return function(a){var b={};d.forEach(function(d){var m=a[d.partitionName];("undefined"===typeof m?"undefined":k(m))!==h&&d.storeKeys.forEach(function(a){b[a]=m[a]})});return b}}
function J(d){var a=!1;d.forEach(function(b){a=a||k(b.storeKeys)!==h;var d=g.default.partitionDefinitions.find(function(a){return b.partitionName===a.partitionName});d||q(b.partitionName+" is not a valid state partition.");k(b.storeKeys)!==h&&(Array.isArray(b.storeKeys)||q("The storeKeys parameter is not an array for "+b.partitionName+"."),b.storeKeys.forEach(function(a){k(d.defaultState[a])===h&&q(a+" is not a valid key in the state partition "+b.partitionName+".")}))});if(a)return I(H(d))}function K(d,
a,b,m,c){return function(d){function e(){if(!(this instanceof e))throw new TypeError("Cannot call a class as a function");var a=(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments);if(!this)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!a||"object"!==typeof a&&"function"!==typeof a?this:a}l(e,d);L(e,[{key:"isCausalityReduxComponent",value:function(){return!0}},{key:"render",value:function(){if("function"===typeof g.default.onListener&&"function"===
typeof a){var d=this.causalityReduxState;this.causalityReduxState=a(c.getState());if(d&&!g.default.shallowEqual(d,this.causalityReduxState))g.default.onListener({nextState:this.causalityReduxState,listenerName:b,partitionName:m})}return M(e.prototype.__proto__||Object.getPrototypeOf(e.prototype),"render",this).call(this)}}]);return e}(d)}function N(d,a,b,c,e,h,k,f){d=u(e,h,k,f)(d);return K(d,e,b,c,g.default.store)}function A(d,a,b,c,e){g.default.store||q("CausalityRedux.createStore must be called before connecting to react components.");
var m="";a.forEach(function(a){""!==m&&(m+=", ");m+=a.partitionName.toString()});var h=F(a),k=J(a);return N(d,a,b,m,k,h,c,e)}function z(d,a,b,c,e,g,f){var m=a,t=e;Array.isArray(a)?(a=[].concat(n(a)),a.forEach(function(a){k(a.changerKeys)===h?a.changerKeys=[]:0===a.changerKeys.length&&(a.changerKeys=void 0);k(a.storeKeys)===h?a.storeKeys=[]:0===a.storeKeys.length&&(a.storeKeys=void 0)}),g=c,f=e,t=b):(m=[],("undefined"===typeof b?"undefined":k(b))===h?b=[]:0===b.length&&(b=void 0),("undefined"===typeof c?
"undefined":k(c))===h?c=[]:0===c.length&&(c=void 0),m.push({partitionName:a,changerKeys:b,storeKeys:c}));return A(d,m,t,g,f)}function B(d,a,b,c,e,g){var m=a,t=e,f=c;Array.isArray(a)?(t=c,g=e,f=b):(m=[],("undefined"===typeof b?"undefined":k(b))===h?b=[]:0===b.length&&(b=void 0),m.push({partitionName:a,changerKeys:void 0,storeKeys:b}));return A(d,m,f,t,g)}function C(d,a,b,c,e,g){var m=a,f=e,t=c;Array.isArray(a)?(f=c,g=e,t=b):(m=[],("undefined"===typeof b?"undefined":k(b))===h?b=[]:0===b.length&&(b=
void 0),m.push({partitionName:a,changerKeys:b,storeKeys:void 0}));return A(d,m,t,f,g)}function D(d){var a=d.module,b=d.uiComponent,c=d.uiComponentName,e=d.partition,f=d.storeKeys,l=d.changerKeys,n=d.hotDisposeHandler;d=d.controllerUIConnections;("undefined"===typeof d?"undefined":k(d))!==h&&("undefined"===typeof b?"undefined":k(b))!==h&&q("Cannot define both controllerUIConnections and uiComponent.");var p=void 0,v=void 0;e&&(v=g.default.shallowCopy(e));("undefined"===typeof d?"undefined":k(d))!==
h&&(Array.isArray(d)||q("controllerUIConnections must be an array."),p=g.default.shallowCopy(d),p.forEach(function(a,b){var d=a;Array.isArray(a)&&(d={uiComponent:a[0]},Array.isArray(a[1])?(d.partitions=a[1],d.uiComponentName=a[2]):(d.partitionName=a[1],d.changerKeys=a[2],d.storeKeys=a[3],d.uiComponentName=a[4]));p[b]=d;v&&(v.defaultState[d.uiComponentName]=null)}));var r=d=e=void 0,u=void 0,w=void 0,x={};if(("undefined"===typeof v?"undefined":k(v))!==h){g.default.createStore(v);var y=g.default.partitionDefinitions.find(function(a){return v.partitionName===
a.partitionName});E&&E(y.partitionName);w=u=g.default.store[y.partitionName];e=w.partitionState;d=w.setState;r=w.getState;w=w.subscribe;("undefined"===typeof f?"undefined":k(f))===h?f=g.default.getKeys(y.defaultState):0===f.length&&(f=void 0);("undefined"===typeof l?"undefined":k(l))===h?l=g.default.getKeys(y.uiServiceFunctions):0===l.length&&(l=void 0);("undefined"===typeof b?"undefined":k(b))!==h&&(("undefined"===typeof c?"undefined":k(c))===h&&q("The component should have uiComponentName as the string name of the component."),
x[c]=z(b,y.partitionName,l,f,c),b=x[c])}("undefined"===typeof p?"undefined":k(p))!==h&&(p.forEach(function(a){var b=[a.uiComponent];a.partitions?b.push(a.partitions):(b.push(a.partitionName),b.push(a.changerKeys),b.push(a.storeKeys));b.push(a.uiComponentName);b=z.apply(void 0,b);x[a.uiComponentName]=b}),("undefined"===typeof d?"undefined":k(d))!==h&&d(x),b=x);("undefined"===typeof a?"undefined":k(a))!==h&&a.hot&&a.hot.dispose(function(){"function"===typeof n&&n()});return{partitionState:e,setState:d,
getState:r,subscribe:w,partitionStore:u,wrappedComponents:x,uiComponent:b}}Object.defineProperty(c,"__esModule",{value:!0});c.isCausalityReduxComponent=void 0;var L=function(){function d(a,b){for(var d=0;d<b.length;d++){var c=b[d];c.enumerable=c.enumerable||!1;c.configurable=!0;"value"in c&&(c.writable=!0);Object.defineProperty(a,c.key,c)}}return function(a,b,c){b&&d(a.prototype,b);c&&d(a,c);return a}}(),M=function a(b,c,e){null===b&&(b=Function.prototype);var f=Object.getOwnPropertyDescriptor(b,
c);if(void 0===f){if(b=Object.getPrototypeOf(b),null!==b)return a(b,c,e)}else{if("value"in f)return f.value;c=f.get;return void 0===c?void 0:c.call(e)}},k="function"===typeof Symbol&&"symbol"===typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"===typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};c.connectChangersAndStateToProps=z;c.connectStateToProps=B;c.connectChangersToProps=C;c.establishControllerConnections=D;f=e(1);var g=(e=e(0))&&
e.__esModule?e:{default:e},h="undefined",E=null,q=function(a){throw Error("react-causality-redux: "+a);};("undefined"===typeof g.default?"undefined":k(g.default))===h&&q("CausalityRedux is undefined");var u=void 0;("undefined"===typeof f.connect?"undefined":k(f.connect))!==h&&(u=f.connect);("undefined"===typeof u?"undefined":k(u))===h&&(("undefined"===typeof ReactRedux?"undefined":k(ReactRedux))===h&&q("ReactRedux is undefined"),u=ReactRedux.connect);var G=function(a){var b=[];a.forEach(function(a){if(k(a.changerKeys)!==
h){var c=void 0;0===a.changerKeys.length?(c=g.default.partitionDefinitions.find(function(b){return a.partitionName===b.partitionName}),c=g.default.getKeys(c.uiServiceFunctions)):c=[].concat(n(a.changerKeys));b.push({partitionName:a.partitionName,changerKeys:c})}});return b};c=c.isCausalityReduxComponent=function(a){return"function"===typeof a&&a.prototype!==h&&k(a.prototype.isCausalityReduxComponent)!==h};g.default.connectChangersAndStateToProps=z;g.default.connectStateToProps=B;g.default.connectChangersToProps=
C;g.default.establishControllerConnections=D;g.default.isCausalityReduxComponent=c}])}]);