Comparing version 2.0.0 to 2.1.0
@@ -5,2 +5,8 @@ # Change Log | ||
## [2.1.0 - 2018-05-10](https://github.com/alonrbar/redux-app/tree/v2.1.0) | ||
### Added | ||
- Re-add the `component` decorator (so that components with no actions can still be declared). | ||
## [2.0.0 - 2018-03-17](https://github.com/alonrbar/redux-app/tree/v2.0.0) | ||
@@ -32,3 +38,3 @@ | ||
## [1.11.1 - 2018-27-2](https://github.com/alonrbar/redux-app/tree/v1.11.1) | ||
## [1.11.1 - 2018-02-27](https://github.com/alonrbar/redux-app/tree/v1.11.1) | ||
@@ -35,0 +41,0 @@ ### Deprecated |
@@ -15,2 +15,9 @@ import { Store, StoreEnhancer } from 'redux'; | ||
/** | ||
* Class decorator. | ||
* | ||
* Mark this class as a redux component. | ||
*/ | ||
export function component(ctor: Function): any; | ||
/** | ||
* Method decorator. | ||
@@ -17,0 +24,0 @@ * |
@@ -430,2 +430,8 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
// CONCATENATED MODULE: ./src/decorators/component.ts | ||
function component_component(ctor) { | ||
componentTemplateInfo_ComponentTemplateInfo.getOrInitInfo(ctor); | ||
} | ||
// CONCATENATED MODULE: ./src/decorators/ignoreState.ts | ||
@@ -517,2 +523,3 @@ | ||
// EXTERNAL MODULE: external "redux" | ||
@@ -1149,2 +1156,3 @@ var external__redux_ = __webpack_require__(2); | ||
/* concated harmony reexport */__webpack_require__.d(__webpack_exports__, "action", function() { return action_action; }); | ||
/* concated harmony reexport */__webpack_require__.d(__webpack_exports__, "component", function() { return component_component; }); | ||
/* concated harmony reexport */__webpack_require__.d(__webpack_exports__, "ignoreState", function() { return ignoreState; }); | ||
@@ -1151,0 +1159,0 @@ /* concated harmony reexport */__webpack_require__.d(__webpack_exports__, "sequence", function() { return sequence; }); |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("redux-app",[],e):"object"==typeof exports?exports["redux-app"]=e():t["redux-app"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function r(t){return"symbol"==typeof t||t instanceof Symbol}function o(t,e,n){return t[e]=n}function i(t,e){return t[e]}function a(t,e){return Object.getOwnPropertySymbols(t).includes(e)&&i(t,e)}function s(t){var e=Object.keys(t);return function(n,r){void 0===n&&(n={});for(var o=!1,i={},a=0,s=e;a<s.length;a++){var c=s[a],u=t[c],p=n[c],f=u(p,r);i[c]=f,o=o||f!==p}return o?i:n}}function c(t){for(var e=Object.keys(t),n=0,r=e;n<r.length;n++){delete t[r[n]]}}function u(t,e,n){for(var r=p(e,n),o=0,i=Object.keys(r);o<i.length;o++){var a=i[o];Object.defineProperty(t,a,r[a])}return t}function p(t,e){for(var n={};t.constructor!==Object;){var r=Object.getOwnPropertyDescriptors(t);if(e&&e.length){for(var o={},i=0,a=Object.keys(r);i<a.length;i++)for(var s=a[i],c=0,u=e;c<u.length;c++){var p=u[c],f=!1;switch(p){case N.None:break;case N.Field:f="function"!=typeof r[s].value&&"function"!=typeof r[s].get;break;case N.Property:f="function"==typeof r[s].get;break;case N.Method:f="function"==typeof r[s].value&&"function"!=typeof r[s].get;break;default:throw new Error("Property flag not supported: "+p)}f&&(o[s]=r[s])}r=o}n=Object.assign(r,n),t=l(t)}return n.constructor&&delete n.constructor,n}function f(t,e){if(t&&t.constructor){return t.constructor[e]}}function d(t,e){if(t&&t.constructor){var n=t.constructor;return r(e)&&Object.getOwnPropertySymbols(n).includes(e)?n[e]:"string"==typeof e&&Object.getOwnPropertyNames(n).includes(e)?n[e]:void 0}}function h(t,e){void 0===e&&(e=!1);for(var n=p(t,[N.Method]),r={},o=0,i=Object.keys(n);o<i.length;o++){var a=i[o];r[a]=n[a].value,e&&(r[a]=r[a].bind(t))}return r}function l(t){if("object"==typeof t)return Object.getPrototypeOf(t);if("function"==typeof t)return t.prototype;throw new Error("Expected an object or a function. Got: "+t)}function g(t){if(!t)return!0;var e=typeof t;return"object"!==e&&"function"!==e}function v(t,e){_.getOrInitInfo(t).actions[e]=!0}function y(t,e){A.getOrInitInfo(t).ignoreState[e]=!0}function b(t,e){_.getOrInitInfo(t).sequences[e]=!0}function m(t,e){if(!e)return function(e,n){return O(e,n,t)};O.call(void 0,t,e)}function O(t,e,n){_.getOrInitInfo(t).childIds[e]=n||P}function w(t,e){if(t instanceof e)return!0;var n=R.getInfo(t);return!(!n||n.originalClass!==e)}Object.defineProperty(e,"__esModule",{value:!0});var j,I=Symbol("REDUX-APP.COMPONENT_INFO"),S=Symbol("REDUX-APP.COMPONENT_TEMPLATE_INFO"),C=Symbol("REDUX-APP.CLASS_INFO"),P=Symbol("REDUX-APP.AUTO_ID"),A=function(){function t(){this.ignoreState={}}return t.getInfo=function(t){if(t)return i(t,C)},t.getOrInitInfo=function(e){var n=t.getInfo(e);return n||(n=o(e,C,new t)),n},t}(),R=function(){function t(t,e,n){this.originalClass=t.constructor,this.dispatch=e,this.id=n}return t.getInfo=function(t){if(t)return i(t,I)},t.initInfo=function(e,n,r,i){var a=new t(n,r,i);return o(e,I,a)},t}(),k=function(){function t(){this.actionNamespace=!0,this.actionNamespaceSeparator=".",this.uppercaseActions=!1}return t}(),x=function(){function t(){this.updateState=!0}return t}();!function(t){t[t.None=0]="None",t[t.Verbose=1]="Verbose",t[t.Debug=2]="Debug",t[t.Warn=5]="Warn",t[t.Silent=10]="Silent"}(j||(j={}));var N,E=function(){function t(){this.logLevel=j.Warn,this.action=new k}return t}(),D=new E,T=function(){function t(){}return t.prototype.verbose=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(j.Verbose)&&console.debug.apply(console,["VERBOSE [redux-app] "+t].concat(e))},t.prototype.debug=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(j.Debug)&&console.log.apply(console,["DEBUG [redux-app] "+t].concat(e))},t.prototype.warn=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(j.Warn)&&console.warn.apply(console,["WARN [redux-app] "+t].concat(e))},t.prototype.shouldLog=function(t){return D.logLevel!==j.None&&!(D.logLevel>t)},t}(),L=new T;!function(t){t.None="None",t.Field="Field",t.Property="Property",t.Method="Method"}(N||(N={}));var _=function(){function t(){this.actions={},this.sequences={},this.childIds={}}return t.getInfo=function(e){if(e){var n=t.getOwnInfo(e);if(n)return n;return t.getBaseInfo(e)?t.initInfo(e):void 0}},t.getOrInitInfo=function(e){var n=t.getInfo(e);return n||t.initInfo(e)},t.getOwnInfo=function(t){return"object"==typeof t?d(t,S):a(t,S)},t.getBaseInfo=function(t){return"object"==typeof t?f(t,S):i(t,S)},t.initInfo=function(e){var n="function"==typeof e,r=n?e:e.constructor,a=i(r,S),s=Object.assign(new t,a);return o(r,S,s)},t}(),M=function(){function t(){}return t.isIgnoredProperty=function(t,e){var n=A.getInfo(t);return n&&n.ignoreState[e]},t.removeIgnoredProps=function(t,e){var n=A.getInfo(e);if(!n)return t;for(var r=0,o=Object.keys(n.ignoreState);r<o.length;r++){delete t[o[r]]}return t},t}(),U=function(){function t(){}return t.nextAvailableId=function(){return--t.autoComponentId},t.getComponentId=function(e,n){var r=n.split(".");if(e&&r.length){var o=_.getInfo(e);if(o){var i=r[r.length-1],a=o.childIds[i];if(a){if(a===P){var s=t.nextAvailableId();return L.verbose("[getComponentId] new component id generated: "+s),o.childIds[i]=s,s}return a}}}},t.autoComponentId=0,t}(),F=n(2),W=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},q=n(3),z="root",B={},V=0,X=function(){function t(t){this.visited=new Set,this.path=z,this.forceRecursion=!1,Object.assign(this,t)}return t}(),G=function(){function t(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.warehouse=new Map,this.initialStateUpdated=!1;var r=this.resolveParameters(t,e),o=r.options,i=r.preLoadedState,a=r.enhancer;if(this.name=this.getAppName(o.name),B[this.name])throw new Error("An app with name '"+this.name+"' already exists.");B[this.name]=this;var s=function(t){return t};this.store=Object(F.createStore)(s,i,a);var c=new Y({appName:this.name}),u=Z.create(this.store,t,c);this.root=u,this.registerComponents(c.createdComponents);var p=new J({componentPaths:Object.keys(c.createdComponents)}),f=K.combineReducersTree(this.root,p);if(o.updateState){var d=this.updateState(p);this.subscriptionDisposer=this.store.subscribe(d)}this.store.replaceReducer(f)}return t.createApp=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return new(t.bind.apply(t,[void 0,e].concat(n)))},t.getComponent=function(e,n,r){var o=t.getApp(r);if(!o)throw new Error("App not found (id: '"+(r||"default")+"')");var i=o.getTypeWarehouse(e);if(n){var a=i.get(n);if(!a)throw new Error("Component not found. Type: "+e.name+". Id: '"+n+"'.");return a}var a=i.values().next().value;if(!a)throw new Error("Component not found. Type: "+e.name+".");return a},t.getApp=function(t){var e=t||"default",n=B[e];return n||L.debug("[ReduxApp] Application '"+e+"' does not exist."),n},t.prototype.dispose=function(){this.subscriptionDisposer&&(this.subscriptionDisposer(),this.subscriptionDisposer=null),B[this.name]&&delete B[this.name]},t.prototype.resolveParameters=function(t,e){var n={};return 0===e.length?(n.options=new x,n.preLoadedState=t):1===e.length?"function"==typeof e[0]?(n.options=new x,n.enhancer=e[0],n.preLoadedState=t):(n.options=Object.assign(new x,e[0]),n.preLoadedState=t):2===e.length?(n.options=Object.assign(new x,e[0]),n.preLoadedState=e[1]):(n.options=Object.assign(new x,e[0]),n.preLoadedState=e[1],n.enhancer=e[2]),n},t.prototype.getAppName=function(t){return t||(Object.keys(B).length?"default_"+ ++V:"default")},t.prototype.registerComponents=function(t){for(var e=0,n=Object.values(t);e<n.length;e++){var r=n[e],o=R.getInfo(r),i=this.getTypeWarehouse(o.originalClass),a=o.id||U.nextAvailableId();i.set(a,r)}},t.prototype.getTypeWarehouse=function(t){return this.warehouse.has(t)||this.warehouse.set(t,new Map),this.warehouse.get(t)},t.prototype.updateState=function(t){var e=this;return function(){var n=Date.now(),r=e.store.getState();e.initialStateUpdated&&t.invoked?e.updateChangedComponents((i={},i[z]=r,i),t.changedComponents):(e.initialStateUpdated=!0,e.updateStateRecursion(e.root,r,new X({forceRecursion:!0}))),t.reset();var o=Date.now();L.debug("[updateState] Component tree updated in "+(o-n)+"ms.");var i}},t.prototype.updateChangedComponents=function(t,e){for(var n=Object.keys(e),r=new X,o=0,i=n;o<i.length;o++){var a=i[o],s=e[a],c=q(t,a);this.updateStateRecursion(s,c,W({},r,{path:a}))}},t.prototype.updateStateRecursion=function(t,e,n){if(t===e)return e;if(g(t)||g(e))return e;if(n.visited.has(t))return t;if(n.visited.add(t),n.forceRecursion||t instanceof Z){var r;r=Array.isArray(t)&&Array.isArray(e)?this.updateArray(t,e,n):this.updateObject(t,e,n)}else t=e,r="Object overwritten.";return r&&r.length&&(L.debug("[updateState] Change in '"+n.path+"'. "+r),L.verbose("[updateState] New state: ",t)),t},t.prototype.updateObject=function(t,e,n){for(var r=[],o=0,i=Object.keys(t);o<i.length;o++){var a=i[o];if(!M.isIgnoredProperty(t,a)&&!e.hasOwnProperty(a)){var s=Object.getOwnPropertyDescriptor(t,a);if(s&&"function"==typeof s.get)continue;"function"==typeof t[a]&&L.warn("[updateState] Function property removed in path: "+n.path+"."+a+". Consider using a method instead."),delete t[a],r.push(a)}}for(var c=[],u=0,p=Object.keys(e);u<p.length;u++){var a=p[u];if(!M.isIgnoredProperty(t,a)){var s=Object.getOwnPropertyDescriptor(t,a);if(!s||"function"!=typeof s.get||"function"==typeof s.set){var f=e[a],d=t[a],h=this.updateStateRecursion(d,f,W({},n,{path:n.path+"."+a}));h!==d&&(t[a]=h,c.push(a))}}}if(c.length||r.length){var l=c.length?"Props assigned: "+c.join(", ")+".":"",g=r.length?"Props deleted: "+r.join(", ")+".":"";return l+(c.length&&r.length?" ":"")+g}return null},t.prototype.updateArray=function(t,e,n){for(var r=[],o=t.length,i=e.length,a=[],s=0;s<Math.min(o,i);s++){var c=e[s],u=t[s],p=this.updateStateRecursion(u,c,W({},n,{path:n.path+"."+s}));p!==u&&(t[s]=p,a.push(s))}if(a.length&&r.push("Assigned item(s) at indexes "+a.join(", ")+"."),i>o){var f=e.slice(o);Array.prototype.push.apply(t,f),r.push("Added "+(i-o)+" item(s) at index "+o+".")}else o>i&&(t.splice(i),r.push("Removed "+(o-i)+" item(s) at index "+i+"."));return r.join(" ")},t.options=D,t}(),H=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},J=function(){function t(t){this.visited=new Set,this.path=z,this.componentPaths=[],this.changedComponents={},this.invoked=!1,Object.assign(this,t)}return t.prototype.reset=function(){c(this.changedComponents),this.invoked=!1},t}(),K=function(){function t(){}return t.createReducer=function(e,n){var r=_.getInfo(n);if(!r)throw new Error("Inconsistent component '"+n.constructor.name+"'. The 'component' class decorator is missing.");var o=t.createMethodsLookup(n,r),i=t.createStateObjectPrototype(e,r),a=R.getInfo(e).id;return function(r){return function(s,c){if(L.verbose("[reducer] Reducer of: "+n.constructor.name+", action: "+c.type+"."),void 0===s)return L.verbose("[reducer] State is undefined, returning initial value."),t.finalizeStateObject(e,e);if(s===n)return L.verbose("[reducer] State equals to component's template, returning initial value."),t.finalizeStateObject(e,e);if(a!==c.id)return L.verbose("[reducer] Component id and action.id don't match ("+a+" !== "+c.id+")."),s;var u=o[c.type];if(!u)return L.verbose("[reducer] No matching action in this reducer, returning previous state."),s;var p=t.createStateObject(s,i);return u.call.apply(u,[p].concat(c.payload)),r(e),L.verbose("[reducer] Reducer invoked, returning new state."),t.finalizeStateObject(p,e)}}},t.combineReducersTree=function(e,n){var r=t.combineReducersRecursion(e,n);return function(t,e){var o=Date.now();n.invoked=!0,L.debug("[rootReducer] Reducing action: "+e.type+".");var i=r(t,e),a=Date.now();return L.debug("[rootReducer] Reducer tree processed in "+(a-o)+"ms."),i}},t.createMethodsLookup=function(t,e){var n=h(t),r={};return Object.keys(e.actions).forEach(function(e){var o=tt.getActionName(t,e);r[o]=n[e]}),r},t.createStateObjectPrototype=function(e,n){for(var r=u({},e,[N.Property]),o=h(e),i=0,a=Object.keys(o);i<a.length;i++){var s=a[i];n.actions[s]?r[s]=t.actionInvokedError:r[s]=o[s].bind(e)}return r},t.actionInvokedError=function(){throw new Error("Actions should not be invoked from within other actions.")},t.createStateObject=function(t,e){for(var n=Object.create(e),r=0,o=Object.keys(t);r<o.length;r++){var i=o[r],a=Object.getOwnPropertyDescriptor(e,i);a&&"function"==typeof a.get&&"function"!=typeof a.set||(n[i]=t[i])}return n},t.finalizeStateObject=function(t,e){L.verbose("[finalizeStateObject] finalizing state.");var n=Object.assign({},t);return n=M.removeIgnoredProps(n,e),L.verbose("[finalizeStateObject] state finalized."),n},t.combineReducersRecursion=function(e,n){if(!g(e)&&!n.visited.has(e)){if(n.visited.add(e),!n.componentPaths.some(function(t){return t.startsWith(n.path)}))return t.identityReducer;var r,o=R.getInfo(e);r=o?o.reducerCreator(function(t){n.changedComponents[n.path]=t}):t.identityReducer;for(var i={},a=0,c=Object.keys(e);a<c.length;a++){var u=c[a],p=t.combineReducersRecursion(e[u],new J(H({},n,{path:""===n.path?u:n.path+"."+u})));"function"==typeof p&&(i[u]=p)}var f=r;if(Object.keys(i).length){var d=s(i);f=function(e,n){var o=r(e,n),i=d(o,n);return t.mergeState(o,i)}}return f}},t.mergeState=function(t,e){if(Array.isArray(t)&&Array.isArray(e)){for(var n=0;n<e.length;n++)t[n]=e[n];return t}return H({},t,e)},t.identityReducer=function(t){return t},t}(),Q=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},Y=function(){function t(t){this.visitedNodes=new Set,this.visitedTemplates=new Map,this.path=z,this.createdComponents={},Object.assign(this,t)}return t}(),Z=function(){function t(e,n,r){if(!_.getInfo(n))throw new Error("Argument 'template' is not a component template. Did you forget to use the decorator?");t.createSelf(this,e,n,r),r.createdComponents[r.path]=this,r.visitedTemplates.set(n,this),L.verbose("[Component] New "+n.constructor.name+" component created. Path: "+r.path),t.createSubComponents(this,e,n,r)}return t.create=function(e,n,r){return r=Object.assign(new Y,r),_.getOrInitInfo(n),new(t.getComponentClass(n))(e,n,r)},t.getComponentClass=function(e){var n=_.getInfo(e);return n.componentClass||(n.componentClass=t.createComponentClass(e)),n.componentClass},t.createComponentClass=function(e){var n=new Function("initCallback",'"use strict";return function '+e.constructor.name+"_ReduxAppComponent() { initCallback(this, arguments); }"),r=n(function(e,n){return t.apply(e,n)});r.prototype=Object.create(t.prototype),r.prototype.constructor=r;var o=tt.createActions(e);return Object.assign(r.prototype,o),r},t.createSelf=function(t,e,n,r){u(t,n,[N.Field,N.Property]);var o=U.getComponentId(r.parentTemplate,r.path),i=R.initInfo(t,n,e.dispatch,o),a=A.getOrInitInfo(t),s=A.getInfo(n)||new A;a.ignoreState=s.ignoreState,i.reducerCreator=K.createReducer(t,n)},t.createSubComponents=function(e,n,r,o){if(!g(e)&&!o.visitedNodes.has(e)){o.visitedNodes.add(e);for(var i=r||e,a=0,s=Object.keys(i);a<s.length;a++){var c=s[a],u=o.path+"."+c,p=i[c];_.getInfo(p)?o.visitedTemplates.has(p)?e[c]=o.visitedTemplates.get(p):e[c]=t.create(n,p,Q({},o,{parentTemplate:r,path:u})):t.createSubComponents(e[c],n,null,Q({},o,{parentTemplate:null,path:u}))}}},t}(),$=n(4),tt=function(){function t(){}return t.createActions=function(e){var n=h(e);if(n){var r=_.getInfo(e),o={};return Object.keys(n).forEach(function(i){o[i]=function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];if(!(this instanceof Z))throw new Error("Component method invoked with non-Component as 'this'. Bound 'this' argument is: "+this);var s=n[i];if(r.actions[i]||r.sequences[i]){var c=R.getInfo(this),u={type:t.getActionName(e,i),id:c?c.id:void 0,payload:o};c.dispatch(u)}if(!r.actions[i])return s.call.apply(s,[this].concat(o))}}),o}},t.getActionName=function(t,e){var n=Object.assign(new k,D.action),r=e,o=t.constructor.name;return n.uppercaseActions&&(r=$(r).toUpperCase(),o=$(o).toUpperCase()),n.actionNamespace&&(r=o+n.actionNamespaceSeparator+r),r},t}();n.d(e,"isInstanceOf",function(){return w}),n.d(e,"action",function(){return v}),n.d(e,"ignoreState",function(){return y}),n.d(e,"sequence",function(){return b}),n.d(e,"withId",function(){return m}),n.d(e,"ActionOptions",function(){return k}),n.d(e,"AppOptions",function(){return x}),n.d(e,"GlobalOptions",function(){return E}),n.d(e,"LogLevel",function(){return j}),n.d(e,"getMethods",function(){return h}),n.d(e,"ReduxApp",function(){return G})},function(t,e){t.exports=require("redux")},function(t,e){t.exports=require("lodash.get")},function(t,e){t.exports=require("lodash.snakecase")}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("redux-app",[],e):"object"==typeof exports?exports["redux-app"]=e():t["redux-app"]=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){"use strict";function r(t){return"symbol"==typeof t||t instanceof Symbol}function o(t,e,n){return t[e]=n}function i(t,e){return t[e]}function a(t,e){return Object.getOwnPropertySymbols(t).includes(e)&&i(t,e)}function c(t){var e=Object.keys(t);return function(n,r){void 0===n&&(n={});for(var o=!1,i={},a=0,c=e;a<c.length;a++){var s=c[a],u=t[s],p=n[s],f=u(p,r);i[s]=f,o=o||f!==p}return o?i:n}}function s(t){for(var e=Object.keys(t),n=0,r=e;n<r.length;n++){delete t[r[n]]}}function u(t,e,n){for(var r=p(e,n),o=0,i=Object.keys(r);o<i.length;o++){var a=i[o];Object.defineProperty(t,a,r[a])}return t}function p(t,e){for(var n={};t.constructor!==Object;){var r=Object.getOwnPropertyDescriptors(t);if(e&&e.length){for(var o={},i=0,a=Object.keys(r);i<a.length;i++)for(var c=a[i],s=0,u=e;s<u.length;s++){var p=u[s],f=!1;switch(p){case E.None:break;case E.Field:f="function"!=typeof r[c].value&&"function"!=typeof r[c].get;break;case E.Property:f="function"==typeof r[c].get;break;case E.Method:f="function"==typeof r[c].value&&"function"!=typeof r[c].get;break;default:throw new Error("Property flag not supported: "+p)}f&&(o[c]=r[c])}r=o}n=Object.assign(r,n),t=l(t)}return n.constructor&&delete n.constructor,n}function f(t,e){if(t&&t.constructor){return t.constructor[e]}}function d(t,e){if(t&&t.constructor){var n=t.constructor;return r(e)&&Object.getOwnPropertySymbols(n).includes(e)?n[e]:"string"==typeof e&&Object.getOwnPropertyNames(n).includes(e)?n[e]:void 0}}function h(t,e){void 0===e&&(e=!1);for(var n=p(t,[E.Method]),r={},o=0,i=Object.keys(n);o<i.length;o++){var a=i[o];r[a]=n[a].value,e&&(r[a]=r[a].bind(t))}return r}function l(t){if("object"==typeof t)return Object.getPrototypeOf(t);if("function"==typeof t)return t.prototype;throw new Error("Expected an object or a function. Got: "+t)}function g(t){if(!t)return!0;var e=typeof t;return"object"!==e&&"function"!==e}function v(t,e){M.getOrInitInfo(t).actions[e]=!0}function y(t){M.getOrInitInfo(t)}function b(t,e){R.getOrInitInfo(t).ignoreState[e]=!0}function m(t,e){M.getOrInitInfo(t).sequences[e]=!0}function O(t,e){if(!e)return function(e,n){return w(e,n,t)};w.call(void 0,t,e)}function w(t,e,n){M.getOrInitInfo(t).childIds[e]=n||A}function j(t,e){if(t instanceof e)return!0;var n=k.getInfo(t);return!(!n||n.originalClass!==e)}Object.defineProperty(e,"__esModule",{value:!0});var I,S=Symbol("REDUX-APP.COMPONENT_INFO"),C=Symbol("REDUX-APP.COMPONENT_TEMPLATE_INFO"),P=Symbol("REDUX-APP.CLASS_INFO"),A=Symbol("REDUX-APP.AUTO_ID"),R=function(){function t(){this.ignoreState={}}return t.getInfo=function(t){if(t)return i(t,P)},t.getOrInitInfo=function(e){var n=t.getInfo(e);return n||(n=o(e,P,new t)),n},t}(),k=function(){function t(t,e,n){this.originalClass=t.constructor,this.dispatch=e,this.id=n}return t.getInfo=function(t){if(t)return i(t,S)},t.initInfo=function(e,n,r,i){var a=new t(n,r,i);return o(e,S,a)},t}(),x=function(){function t(){this.actionNamespace=!0,this.actionNamespaceSeparator=".",this.uppercaseActions=!1}return t}(),N=function(){function t(){this.updateState=!0}return t}();!function(t){t[t.None=0]="None",t[t.Verbose=1]="Verbose",t[t.Debug=2]="Debug",t[t.Warn=5]="Warn",t[t.Silent=10]="Silent"}(I||(I={}));var E,D=function(){function t(){this.logLevel=I.Warn,this.action=new x}return t}(),T=new D,L=function(){function t(){}return t.prototype.verbose=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(I.Verbose)&&console.debug.apply(console,["VERBOSE [redux-app] "+t].concat(e))},t.prototype.debug=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(I.Debug)&&console.log.apply(console,["DEBUG [redux-app] "+t].concat(e))},t.prototype.warn=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.shouldLog(I.Warn)&&console.warn.apply(console,["WARN [redux-app] "+t].concat(e))},t.prototype.shouldLog=function(t){return T.logLevel!==I.None&&!(T.logLevel>t)},t}(),_=new L;!function(t){t.None="None",t.Field="Field",t.Property="Property",t.Method="Method"}(E||(E={}));var M=function(){function t(){this.actions={},this.sequences={},this.childIds={}}return t.getInfo=function(e){if(e){var n=t.getOwnInfo(e);if(n)return n;return t.getBaseInfo(e)?t.initInfo(e):void 0}},t.getOrInitInfo=function(e){var n=t.getInfo(e);return n||t.initInfo(e)},t.getOwnInfo=function(t){return"object"==typeof t?d(t,C):a(t,C)},t.getBaseInfo=function(t){return"object"==typeof t?f(t,C):i(t,C)},t.initInfo=function(e){var n="function"==typeof e,r=n?e:e.constructor,a=i(r,C),c=Object.assign(new t,a);return o(r,C,c)},t}(),U=function(){function t(){}return t.isIgnoredProperty=function(t,e){var n=R.getInfo(t);return n&&n.ignoreState[e]},t.removeIgnoredProps=function(t,e){var n=R.getInfo(e);if(!n)return t;for(var r=0,o=Object.keys(n.ignoreState);r<o.length;r++){delete t[o[r]]}return t},t}(),F=function(){function t(){}return t.nextAvailableId=function(){return--t.autoComponentId},t.getComponentId=function(e,n){var r=n.split(".");if(e&&r.length){var o=M.getInfo(e);if(o){var i=r[r.length-1],a=o.childIds[i];if(a){if(a===A){var c=t.nextAvailableId();return _.verbose("[getComponentId] new component id generated: "+c),o.childIds[i]=c,c}return a}}}},t.autoComponentId=0,t}(),W=n(2),q=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},z=n(3),B="root",V={},X=0,G=function(){function t(t){this.visited=new Set,this.path=B,this.forceRecursion=!1,Object.assign(this,t)}return t}(),H=function(){function t(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];this.warehouse=new Map,this.initialStateUpdated=!1;var r=this.resolveParameters(t,e),o=r.options,i=r.preLoadedState,a=r.enhancer;if(this.name=this.getAppName(o.name),V[this.name])throw new Error("An app with name '"+this.name+"' already exists.");V[this.name]=this;var c=function(t){return t};this.store=Object(W.createStore)(c,i,a);var s=new Z({appName:this.name}),u=$.create(this.store,t,s);this.root=u,this.registerComponents(s.createdComponents);var p=new K({componentPaths:Object.keys(s.createdComponents)}),f=Q.combineReducersTree(this.root,p);if(o.updateState){var d=this.updateState(p);this.subscriptionDisposer=this.store.subscribe(d)}this.store.replaceReducer(f)}return t.createApp=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return new(t.bind.apply(t,[void 0,e].concat(n)))},t.getComponent=function(e,n,r){var o=t.getApp(r);if(!o)throw new Error("App not found (id: '"+(r||"default")+"')");var i=o.getTypeWarehouse(e);if(n){var a=i.get(n);if(!a)throw new Error("Component not found. Type: "+e.name+". Id: '"+n+"'.");return a}var a=i.values().next().value;if(!a)throw new Error("Component not found. Type: "+e.name+".");return a},t.getApp=function(t){var e=t||"default",n=V[e];return n||_.debug("[ReduxApp] Application '"+e+"' does not exist."),n},t.prototype.dispose=function(){this.subscriptionDisposer&&(this.subscriptionDisposer(),this.subscriptionDisposer=null),V[this.name]&&delete V[this.name]},t.prototype.resolveParameters=function(t,e){var n={};return 0===e.length?(n.options=new N,n.preLoadedState=t):1===e.length?"function"==typeof e[0]?(n.options=new N,n.enhancer=e[0],n.preLoadedState=t):(n.options=Object.assign(new N,e[0]),n.preLoadedState=t):2===e.length?(n.options=Object.assign(new N,e[0]),n.preLoadedState=e[1]):(n.options=Object.assign(new N,e[0]),n.preLoadedState=e[1],n.enhancer=e[2]),n},t.prototype.getAppName=function(t){return t||(Object.keys(V).length?"default_"+ ++X:"default")},t.prototype.registerComponents=function(t){for(var e=0,n=Object.values(t);e<n.length;e++){var r=n[e],o=k.getInfo(r),i=this.getTypeWarehouse(o.originalClass),a=o.id||F.nextAvailableId();i.set(a,r)}},t.prototype.getTypeWarehouse=function(t){return this.warehouse.has(t)||this.warehouse.set(t,new Map),this.warehouse.get(t)},t.prototype.updateState=function(t){var e=this;return function(){var n=Date.now(),r=e.store.getState();e.initialStateUpdated&&t.invoked?e.updateChangedComponents((i={},i[B]=r,i),t.changedComponents):(e.initialStateUpdated=!0,e.updateStateRecursion(e.root,r,new G({forceRecursion:!0}))),t.reset();var o=Date.now();_.debug("[updateState] Component tree updated in "+(o-n)+"ms.");var i}},t.prototype.updateChangedComponents=function(t,e){for(var n=Object.keys(e),r=new G,o=0,i=n;o<i.length;o++){var a=i[o],c=e[a],s=z(t,a);this.updateStateRecursion(c,s,q({},r,{path:a}))}},t.prototype.updateStateRecursion=function(t,e,n){if(t===e)return e;if(g(t)||g(e))return e;if(n.visited.has(t))return t;if(n.visited.add(t),n.forceRecursion||t instanceof $){var r;r=Array.isArray(t)&&Array.isArray(e)?this.updateArray(t,e,n):this.updateObject(t,e,n)}else t=e,r="Object overwritten.";return r&&r.length&&(_.debug("[updateState] Change in '"+n.path+"'. "+r),_.verbose("[updateState] New state: ",t)),t},t.prototype.updateObject=function(t,e,n){for(var r=[],o=0,i=Object.keys(t);o<i.length;o++){var a=i[o];if(!U.isIgnoredProperty(t,a)&&!e.hasOwnProperty(a)){var c=Object.getOwnPropertyDescriptor(t,a);if(c&&"function"==typeof c.get)continue;"function"==typeof t[a]&&_.warn("[updateState] Function property removed in path: "+n.path+"."+a+". Consider using a method instead."),delete t[a],r.push(a)}}for(var s=[],u=0,p=Object.keys(e);u<p.length;u++){var a=p[u];if(!U.isIgnoredProperty(t,a)){var c=Object.getOwnPropertyDescriptor(t,a);if(!c||"function"!=typeof c.get||"function"==typeof c.set){var f=e[a],d=t[a],h=this.updateStateRecursion(d,f,q({},n,{path:n.path+"."+a}));h!==d&&(t[a]=h,s.push(a))}}}if(s.length||r.length){var l=s.length?"Props assigned: "+s.join(", ")+".":"",g=r.length?"Props deleted: "+r.join(", ")+".":"";return l+(s.length&&r.length?" ":"")+g}return null},t.prototype.updateArray=function(t,e,n){for(var r=[],o=t.length,i=e.length,a=[],c=0;c<Math.min(o,i);c++){var s=e[c],u=t[c],p=this.updateStateRecursion(u,s,q({},n,{path:n.path+"."+c}));p!==u&&(t[c]=p,a.push(c))}if(a.length&&r.push("Assigned item(s) at indexes "+a.join(", ")+"."),i>o){var f=e.slice(o);Array.prototype.push.apply(t,f),r.push("Added "+(i-o)+" item(s) at index "+o+".")}else o>i&&(t.splice(i),r.push("Removed "+(o-i)+" item(s) at index "+i+"."));return r.join(" ")},t.options=T,t}(),J=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},K=function(){function t(t){this.visited=new Set,this.path=B,this.componentPaths=[],this.changedComponents={},this.invoked=!1,Object.assign(this,t)}return t.prototype.reset=function(){s(this.changedComponents),this.invoked=!1},t}(),Q=function(){function t(){}return t.createReducer=function(e,n){var r=M.getInfo(n);if(!r)throw new Error("Inconsistent component '"+n.constructor.name+"'. The 'component' class decorator is missing.");var o=t.createMethodsLookup(n,r),i=t.createStateObjectPrototype(e,r),a=k.getInfo(e).id;return function(r){return function(c,s){if(_.verbose("[reducer] Reducer of: "+n.constructor.name+", action: "+s.type+"."),void 0===c)return _.verbose("[reducer] State is undefined, returning initial value."),t.finalizeStateObject(e,e);if(c===n)return _.verbose("[reducer] State equals to component's template, returning initial value."),t.finalizeStateObject(e,e);if(a!==s.id)return _.verbose("[reducer] Component id and action.id don't match ("+a+" !== "+s.id+")."),c;var u=o[s.type];if(!u)return _.verbose("[reducer] No matching action in this reducer, returning previous state."),c;var p=t.createStateObject(c,i);return u.call.apply(u,[p].concat(s.payload)),r(e),_.verbose("[reducer] Reducer invoked, returning new state."),t.finalizeStateObject(p,e)}}},t.combineReducersTree=function(e,n){var r=t.combineReducersRecursion(e,n);return function(t,e){var o=Date.now();n.invoked=!0,_.debug("[rootReducer] Reducing action: "+e.type+".");var i=r(t,e),a=Date.now();return _.debug("[rootReducer] Reducer tree processed in "+(a-o)+"ms."),i}},t.createMethodsLookup=function(t,e){var n=h(t),r={};return Object.keys(e.actions).forEach(function(e){var o=et.getActionName(t,e);r[o]=n[e]}),r},t.createStateObjectPrototype=function(e,n){for(var r=u({},e,[E.Property]),o=h(e),i=0,a=Object.keys(o);i<a.length;i++){var c=a[i];n.actions[c]?r[c]=t.actionInvokedError:r[c]=o[c].bind(e)}return r},t.actionInvokedError=function(){throw new Error("Actions should not be invoked from within other actions.")},t.createStateObject=function(t,e){for(var n=Object.create(e),r=0,o=Object.keys(t);r<o.length;r++){var i=o[r],a=Object.getOwnPropertyDescriptor(e,i);a&&"function"==typeof a.get&&"function"!=typeof a.set||(n[i]=t[i])}return n},t.finalizeStateObject=function(t,e){_.verbose("[finalizeStateObject] finalizing state.");var n=Object.assign({},t);return n=U.removeIgnoredProps(n,e),_.verbose("[finalizeStateObject] state finalized."),n},t.combineReducersRecursion=function(e,n){if(!g(e)&&!n.visited.has(e)){if(n.visited.add(e),!n.componentPaths.some(function(t){return t.startsWith(n.path)}))return t.identityReducer;var r,o=k.getInfo(e);r=o?o.reducerCreator(function(t){n.changedComponents[n.path]=t}):t.identityReducer;for(var i={},a=0,s=Object.keys(e);a<s.length;a++){var u=s[a],p=t.combineReducersRecursion(e[u],new K(J({},n,{path:""===n.path?u:n.path+"."+u})));"function"==typeof p&&(i[u]=p)}var f=r;if(Object.keys(i).length){var d=c(i);f=function(e,n){var o=r(e,n),i=d(o,n);return t.mergeState(o,i)}}return f}},t.mergeState=function(t,e){if(Array.isArray(t)&&Array.isArray(e)){for(var n=0;n<e.length;n++)t[n]=e[n];return t}return J({},t,e)},t.identityReducer=function(t){return t},t}(),Y=this&&this.__assign||Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t},Z=function(){function t(t){this.visitedNodes=new Set,this.visitedTemplates=new Map,this.path=B,this.createdComponents={},Object.assign(this,t)}return t}(),$=function(){function t(e,n,r){if(!M.getInfo(n))throw new Error("Argument 'template' is not a component template. Did you forget to use the decorator?");t.createSelf(this,e,n,r),r.createdComponents[r.path]=this,r.visitedTemplates.set(n,this),_.verbose("[Component] New "+n.constructor.name+" component created. Path: "+r.path),t.createSubComponents(this,e,n,r)}return t.create=function(e,n,r){return r=Object.assign(new Z,r),M.getOrInitInfo(n),new(t.getComponentClass(n))(e,n,r)},t.getComponentClass=function(e){var n=M.getInfo(e);return n.componentClass||(n.componentClass=t.createComponentClass(e)),n.componentClass},t.createComponentClass=function(e){var n=new Function("initCallback",'"use strict";return function '+e.constructor.name+"_ReduxAppComponent() { initCallback(this, arguments); }"),r=n(function(e,n){return t.apply(e,n)});r.prototype=Object.create(t.prototype),r.prototype.constructor=r;var o=et.createActions(e);return Object.assign(r.prototype,o),r},t.createSelf=function(t,e,n,r){u(t,n,[E.Field,E.Property]);var o=F.getComponentId(r.parentTemplate,r.path),i=k.initInfo(t,n,e.dispatch,o),a=R.getOrInitInfo(t),c=R.getInfo(n)||new R;a.ignoreState=c.ignoreState,i.reducerCreator=Q.createReducer(t,n)},t.createSubComponents=function(e,n,r,o){if(!g(e)&&!o.visitedNodes.has(e)){o.visitedNodes.add(e);for(var i=r||e,a=0,c=Object.keys(i);a<c.length;a++){var s=c[a],u=o.path+"."+s,p=i[s];M.getInfo(p)?o.visitedTemplates.has(p)?e[s]=o.visitedTemplates.get(p):e[s]=t.create(n,p,Y({},o,{parentTemplate:r,path:u})):t.createSubComponents(e[s],n,null,Y({},o,{parentTemplate:null,path:u}))}}},t}(),tt=n(4),et=function(){function t(){}return t.createActions=function(e){var n=h(e);if(n){var r=M.getInfo(e),o={};return Object.keys(n).forEach(function(i){o[i]=function(){for(var o=[],a=0;a<arguments.length;a++)o[a]=arguments[a];if(!(this instanceof $))throw new Error("Component method invoked with non-Component as 'this'. Bound 'this' argument is: "+this);var c=n[i];if(r.actions[i]||r.sequences[i]){var s=k.getInfo(this),u={type:t.getActionName(e,i),id:s?s.id:void 0,payload:o};s.dispatch(u)}if(!r.actions[i])return c.call.apply(c,[this].concat(o))}}),o}},t.getActionName=function(t,e){var n=Object.assign(new x,T.action),r=e,o=t.constructor.name;return n.uppercaseActions&&(r=tt(r).toUpperCase(),o=tt(o).toUpperCase()),n.actionNamespace&&(r=o+n.actionNamespaceSeparator+r),r},t}();n.d(e,"isInstanceOf",function(){return j}),n.d(e,"action",function(){return v}),n.d(e,"component",function(){return y}),n.d(e,"ignoreState",function(){return b}),n.d(e,"sequence",function(){return m}),n.d(e,"withId",function(){return O}),n.d(e,"ActionOptions",function(){return x}),n.d(e,"AppOptions",function(){return N}),n.d(e,"GlobalOptions",function(){return D}),n.d(e,"LogLevel",function(){return I}),n.d(e,"getMethods",function(){return h}),n.d(e,"ReduxApp",function(){return H})},function(t,e){t.exports=require("redux")},function(t,e){t.exports=require("lodash.get")},function(t,e){t.exports=require("lodash.snakecase")}])}); |
{ | ||
"name": "redux-app", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Type-safe, DRY and OO redux. Implemented with typescript.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -27,2 +27,3 @@ # redux-app | ||
```javascript | ||
@component | ||
class App { | ||
@@ -32,2 +33,3 @@ counter = new Counter(); | ||
@component | ||
class Counter { | ||
@@ -68,3 +70,3 @@ value = 0; | ||
To make it easier to debug, each generated component name follows the following pattern: OriginalClassName_ReduxAppComponent. If while debugging you don't see the _ReduxAppComponent suffix it means the class was not replaced by an underlying component and is probably lacking a decorator (@action or @sequence). | ||
To make it easier to debug, each generated component name follows the following pattern: OriginalClassName_ReduxAppComponent (if while debugging you don't see the _ReduxAppComponent suffix it means the class was not replaced by an underlying component and is probably lacking a decorator, any of the following will do: @component, @action or @sequence). | ||
@@ -115,2 +117,3 @@ _Reading the source tip #1: There are two main classes in redux-app. The first is ReduxApp and the second is Component._ | ||
```javascript | ||
@component | ||
class MyComponent { | ||
@@ -157,2 +160,3 @@ | ||
```javascript | ||
@component | ||
export class App { | ||
@@ -243,2 +247,3 @@ | ||
```javascript | ||
@component | ||
class ComputedGreeter { | ||
@@ -266,13 +271,9 @@ | ||
```javascript | ||
@component | ||
class MyComponent { | ||
public storeMe = 'hello'; | ||
public storeMe = 'I am stored'; | ||
@ignoreState | ||
public ignoreMe = 'not stored'; | ||
@action | ||
public changeState() { | ||
this.storeMe = 'I am stored'; | ||
} | ||
} | ||
@@ -282,4 +283,4 @@ | ||
console.log(app.root); // { storeMe: 'hello', ignoreMe: 'not stored' } | ||
console.log(app.store.getState()); // { storeMe: 'hello' } | ||
console.log(app.root); // { storeMe: 'I am stored', ignoreMe: 'not stored' } | ||
console.log(app.store.getState()); // { storeMe: 'I am stored' } | ||
``` | ||
@@ -294,7 +295,5 @@ | ||
```javascript | ||
@component | ||
class MyComponent { | ||
@action | ||
public someAction() { | ||
// ... | ||
} | ||
// ... | ||
} | ||
@@ -311,7 +310,5 @@ | ||
```javascript | ||
@component | ||
class MyComponent { | ||
@action | ||
public someAction() { | ||
// ... | ||
} | ||
// ... | ||
} | ||
@@ -318,0 +315,0 @@ |
@@ -0,0 +0,0 @@ export * from './actions'; |
export * from './action'; | ||
export * from './component'; | ||
export * from './ignoreState'; | ||
export * from './sequence'; | ||
export * from './withId'; |
export { isInstanceOf } from './components'; | ||
export { action, ignoreState, sequence, withId } from './decorators'; | ||
export { action, component, ignoreState, sequence, withId } from './decorators'; | ||
export { ActionOptions, AppOptions, GlobalOptions, LogLevel } from './options'; | ||
export { getMethods } from './utils'; | ||
export { ReduxApp } from './reduxApp'; |
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
248370
32
2489
415