Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-app

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-app - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

dist/redux-app.js

2

dist/index.d.ts

@@ -6,2 +6,4 @@ import { Store, StoreEnhancer } from 'redux';

export declare function withId(id?: any): PropertyDecorator;
export declare class ReduxApp<T> {

@@ -8,0 +10,0 @@

2

dist/redux-app.min.js

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

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("redux-app",[],t):"object"==typeof exports?exports["redux-app"]=t():e["redux-app"]=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=3)}([function(e,t,n){"use strict";function o(e){return c.assertComponentSchema(e),Object.assign({},new s,t.globalOptions.schema,u.getConstructorProp(e,t.COMPONENT_SCHEMA_OPTIONS))}function r(e,t){var n=o(t),r=e,c=t.constructor.name;return n.uppercaseActions&&(r=i(r).toUpperCase(),c=i(c).toUpperCase()),n.actionNamespace&&(r=c+"."+r),r}Object.defineProperty(t,"__esModule",{value:!0});var c=n(1),u=n(2),i=n(5);t.COMPONENT_SCHEMA_OPTIONS=Symbol("COMPONENT_SCHEMA_OPTIONS");var s=function(){function e(){this.actionNamespace=!0,this.uppercaseActions=!0,this.updateState=!0}return e}();t.SchemaOptions=s,t.getSchemaOptions=o,t.getActionName=r;var a;!function(e){e[e.None=0]="None",e[e.Verbose=1]="Verbose",e[e.Debug=2]="Debug",e[e.Silent=10]="Silent"}(a=t.LogLevel||(t.LogLevel={}));var p=function(){function e(){this.logLevel=a.Silent,this.schema=new s}return e}();t.GlobalOptions=p,t.globalOptions=new p},function(e,t,n){"use strict";function o(e){if("function"!=typeof e)return function(t){return u(t,e)};u.call(void 0,e)}function r(e){return s.getConstructorProp(e,a)}function c(e){if(!r(e))throw new Error("Invalid argument. component expected.")}function u(e,t){if(s.getArgumentNames(e).length)throw new Error("componentSchema classes must have a parameter-less constructor");e[a]=!0,e[i.COMPONENT_SCHEMA_OPTIONS]=t}Object.defineProperty(t,"__esModule",{value:!0});var i=n(0),s=n(2),a=Symbol("COMPONENT_SCHEMA");t.component=o,t.isComponentSchema=r,t.assertComponentSchema=c},function(e,t,n){"use strict";function o(e){var t,n=/^function\s*?[^\(]*?\(\s*?([^\)]*?)\)/m,o=/^class[\s\S]*?constructor\s*?[^\(]*?\(\s*?([^\)]*?)\)/m,r=e.toString().match(n),c=e.toString().match(o);if(c&&c.length)t=c[1];else{if(!r||!r.length)return[];t=r[1]}return t=t.split(",").map(function(e){return e.trim()}).filter(function(e){return""!==e})}function r(e){if(e)return e.prototype||e.constructor.prototype}function c(e){if(e){var t=r(e);if(t){for(var n={},o=0,c=Object.keys(t);o<c.length;o++){var u=c[o];"function"==typeof t[u]&&(n[u]=t[u])}return n}}}function u(e,t){return"string"==typeof t&&(t=t.replace(/\[|\]/g,".").split(".").filter(function(e){return"string"==typeof e&&""!==e.trim()})),t.reduce(function(e,t){if("object"==typeof e&&t)return e[t.toString()]},e)}function i(e,t){return e&&e.constructor&&e.constructor[t]}Object.defineProperty(t,"__esModule",{value:!0}),t.getArgumentNames=o,t.getPrototype=r,t.getMethods=c,t.getProp=u,t.getConstructorProp=i},function(e,t,n){e.exports=n(4)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(1);t.component=o.component;var r=n(0);t.SchemaOptions=r.SchemaOptions,t.GlobalOptions=r.GlobalOptions,t.LogLevel=r.LogLevel;var c=n(6);t.ReduxApp=c.ReduxApp},function(e,t){e.exports=require("lodash.snakecase")},function(e,t,n){"use strict";var o=this&&this.__assign||Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e};Object.defineProperty(t,"__esModule",{value:!0});var r=n(7),c=n(8),u=n(0),i=n(10),s=function(){function e(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var o=function(){};this.store=r.createStore.apply(void 0,[o].concat(t));var u=new c.Component(this.store,e,[]);this.root=u;var i=this.getReducer(u);this.store.replaceReducer(i)}return e.prototype.getReducer=function(e){for(var t=e[c.REDUCER],n={},r=0,u=Object.keys(e);r<u.length;r++){var s=u[r];e[s]instanceof c.Component&&(n[s]=this.getReducer(e[s]))}if(Object.keys(n).length){var a=i.simpleCombineReducers(n);return function(e,n){var r=t(e,n),c=a(e,n);return o({},r,c)}}return t},e.options=u.globalOptions,e}();t.ReduxApp=s},function(e,t){e.exports=require("redux")},function(e,t,n){"use strict";function o(e,n,o,r){for(var s=0,a=Object.keys(o);s<a.length;s++){var d=a[s];e[d]=o[d]}var v=f.getPrototype(e),g=c(n.dispatch,o);if(Object.assign(v,g),e[t.REDUCER]=u(o),p.getSchemaOptions(o).updateState){var h=n.subscribe(function(){return i(e,n.getState(),r)});e[l].push({dispose:function(){return h()}})}}function r(e,t,n,o){for(var r=0,c=Object.keys(n);r<c.length;r++){var u=c[r],i=n[u];s.isComponentSchema(i)&&(e[u]=new d(t,i,o.concat([u])))}}function c(e,t){var n=f.getMethods(t);if(n){var o={};return Object.keys(n).forEach(function(n){o[n]=function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];e({type:p.getActionName(n,t),payload:o})}}),o}}function u(e){var t=f.getMethods(e),n={};return Object.keys(t).forEach(function(t){var o=p.getActionName(t,e);n[o]=t}),function(o,r){if(a.verbose("[reducer] reducer of: "+e.constructor.name+", action: "+r.type),void 0===o)return a.verbose("[reducer] state is undefined, returning initial value"),e;var c=n[r.type],u=t[c];if(!u)return a.verbose("[reducer] no matching action in this reducer, returning previous state"),o;var i=Object.assign({},o);return u.call.apply(u,[i].concat(r.payload)),a.verbose("[reducer] reducer invoked returning new state"),i}}function i(e,t,n){a.verbose("[updateState] updating component in path: ",n.join("."));var o=e,r=f.getProp(t,n),c=[],u=[];a.verbose("[updateState] store before: ",r),a.verbose("[updateState] component before: ",e),Object.keys(r).forEach(function(e){o[e]===r[e]||o[e]instanceof d||(o[e]=r[e],u.push(e))}),Object.keys(e).forEach(function(e){void 0===r[e]&&(delete o[e],c.push(e))}),c.length||u.length?(a.verbose("[updateState] store after: ",r),a.verbose("[updateState] component after: ",e),a.debug("[updateState] state of "+n.join(".")+" changed"),c.length?a.debug("[updateState] props deleted: ",c):a.verbose("[updateState] props deleted: ",c),u.length?a.debug("[updateState] props assigned: ",u):a.verbose("[updateState] props assigned: ",u)):a.verbose("[updateState] no change")}Object.defineProperty(t,"__esModule",{value:!0});var s=n(1),a=n(9),p=n(0),f=n(2);t.REDUCER=Symbol("REDUCER");var l=Symbol("DISPOSE"),d=function(){function e(e,t,n){if(!s.isComponentSchema(t))throw new Error("Argument 'schema' is not a component schema. Did you forget to use the decorator?");this[l]=[],o(this,e,t,n),r(this,e,t,n),a.debug("[Component] new "+t.constructor.name+" component created. path: "+n.join("."))}return e.prototype.disposeComponent=function(){for(var e=this[l];e.length;){var t=e.pop();t&&t.dispose&&t.dispose()}},e}();t.Component=d},function(e,t,n){"use strict";function o(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];c(u.LogLevel.Debug)&&console.log.apply(console,["[ReduxApp] [DEBUG] "+e].concat(t))}function r(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];c(u.LogLevel.Verbose)&&console.log.apply(console,["[ReduxApp] [VERBOSE] "+e].concat(t))}function c(e){return u.globalOptions.logLevel!==u.LogLevel.None&&!(u.globalOptions.logLevel>e)}Object.defineProperty(t,"__esModule",{value:!0});var u=n(0);t.debug=o,t.verbose=r},function(e,t,n){"use strict";function o(e){var t=Object.keys(e);return function(n,o){void 0===n&&(n={});for(var r=!1,c={},u=0,i=t;u<i.length;u++){var s=i[u],a=e[s],p=n[s],f=a(p,o);c[s]=f,r=r||f!==p}return r?c:n}}Object.defineProperty(t,"__esModule",{value:!0}),t.simpleCombineReducers=o}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("redux-app",[],t):"object"==typeof exports?exports["redux-app"]=t():e["redux-app"]=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,o){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:o})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.REDUCER=Symbol("REDUX-APP.COMPONENT.REDUCER"),t.DISPOSE=Symbol("REDUX-APP.COMPONENT.DISPOSE"),t.COMPONENT_SCHEMA=Symbol("REDUX-APP.COMPONENT_SCHEMA"),t.COMPONENT_SCHEMA_OPTIONS=Symbol("REDUX-APP.COMPONENT_SCHEMA.OPTIONS"),t.WITH_ID=Symbol("REDUX-APP.COMPONENT_SCHEMA.WITH_ID"),t.AUTO_ID=Symbol("REDUX-APP.COMPONENT_SCHEMA.AUTO_ID")},function(e,t,n){"use strict";function o(e){return i.assertComponentSchema(e),Object.assign({},new a,t.globalOptions.schema,c.getConstructorProp(e,u.COMPONENT_SCHEMA_OPTIONS))}function r(e,t){var n=o(t),r=e,i=t.constructor.name;return n.uppercaseActions&&(r=s(r).toUpperCase(),i=s(i).toUpperCase()),n.actionNamespace&&(r=i+"."+r),r}Object.defineProperty(t,"__esModule",{value:!0});var i=n(2),c=n(3),u=n(0),s=n(6),a=function(){function e(){this.actionNamespace=!0,this.uppercaseActions=!0,this.updateState=!0}return e}();t.SchemaOptions=a,t.getSchemaOptions=o,t.getActionName=r;var p;!function(e){e[e.None=0]="None",e[e.Verbose=1]="Verbose",e[e.Debug=2]="Debug",e[e.Silent=10]="Silent"}(p=t.LogLevel||(t.LogLevel={}));var f=function(){function e(){this.logLevel=p.Silent,this.schema=new a}return e}();t.GlobalOptions=f,t.globalOptions=new f},function(e,t,n){"use strict";function o(e){if("function"!=typeof e)return function(t){return c(t,e)};c.call(void 0,e)}function r(e){return u.getConstructorProp(e,s.COMPONENT_SCHEMA)}function i(e,t){if(!r(e))throw new Error(t||"Invalid argument. component expected.")}function c(e,t){if(u.getArgumentNames(e).length)throw new Error("componentSchema classes must have a parameter-less constructor");e[s.COMPONENT_SCHEMA]=!0,e[s.COMPONENT_SCHEMA_OPTIONS]=t}Object.defineProperty(t,"__esModule",{value:!0});var u=n(3),s=n(0);t.component=o,t.isComponentSchema=r,t.assertComponentSchema=i},function(e,t,n){"use strict";function o(e){var t,n=/^function\s*?[^\(]*?\(\s*?([^\)]*?)\)/m,o=/^class[\s\S]*?constructor\s*?[^\(]*?\(\s*?([^\)]*?)\)/m,r=e.toString().match(n),i=e.toString().match(o);if(i&&i.length)t=i[1];else{if(!r||!r.length)return[];t=r[1]}return t=t.split(",").map(function(e){return e.trim()}).filter(function(e){return""!==e})}function r(e){if(e)return e.prototype||e.constructor.prototype}function i(e){if(e){var t=r(e);if(t){for(var n={},o=0,i=Object.keys(t);o<i.length;o++){var c=i[o];"function"==typeof t[c]&&(n[c]=t[c])}return n}}}function c(e,t){return"string"==typeof t&&(t=t.replace(/\[|\]/g,".").split(".").filter(function(e){return"string"==typeof e&&""!==e.trim()})),t.reduce(function(e,t){if("object"==typeof e&&t)return e[t.toString()]},e)}function u(e,t){return e&&e.constructor&&e.constructor[t]}Object.defineProperty(t,"__esModule",{value:!0}),t.getArgumentNames=o,t.getPrototype=r,t.getMethods=i,t.getProp=c,t.getConstructorProp=u},function(e,t,n){e.exports=n(5)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=n(2);t.component=o.component;var r=n(1);t.SchemaOptions=r.SchemaOptions,t.GlobalOptions=r.GlobalOptions,t.LogLevel=r.LogLevel;var i=n(7);t.ReduxApp=i.ReduxApp;var c=n(12);t.withId=c.withId},function(e,t){e.exports=require("lodash.snakecase")},function(e,t,n){"use strict";var o=this&&this.__assign||Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++){t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e};Object.defineProperty(t,"__esModule",{value:!0});var r=n(8),i=n(9),c=n(1),u=n(11),s=n(0),a=function(){function e(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var o=function(){};this.store=r.createStore.apply(void 0,[o].concat(t));var c=new i.Component(this.store,e,null,[]);this.root=c;var u=this.getReducer(c);this.store.replaceReducer(u)}return e.prototype.getReducer=function(e){for(var t=e[s.REDUCER],n={},r=0,c=Object.keys(e);r<c.length;r++){var a=c[r];e[a]instanceof i.Component&&(n[a]=this.getReducer(e[a]))}if(Object.keys(n).length){var p=u.simpleCombineReducers(n);return function(e,n){var r=t(e,n),i=p(e,n);return o({},r,i)}}return t},e.options=c.globalOptions,e}();t.ReduxApp=a},function(e,t){e.exports=require("redux")},function(e,t,n){"use strict";function o(e,t,n,o,r){for(var s=0,a=Object.keys(n);s<a.length;s++){var p=a[s];e[p]=n[p]}var l=i(t.dispatch,n,o,r);if(Object.assign(e,l),e[d.REDUCER]=c(n,o,r),f.getSchemaOptions(n).updateState){var v=t.subscribe(function(){return u(e,t.getState(),r)});e[d.DISPOSE].push({dispose:function(){return v()}})}}function r(e,t,n,o){for(var r=0,i=Object.keys(n);r<i.length;r++){var c=i[r],u=n[c];a.isComponentSchema(u)&&(e[c]=new v(t,u,n,o.concat([c])))}}function i(e,t,n,o){var r=l.getMethods(t);if(r){var i=s(n,o),c={};return Object.keys(r).forEach(function(n){c[n]=function(){for(var o=[],r=0;r<arguments.length;r++)o[r]=arguments[r];e({type:f.getActionName(n,t),id:i,payload:o})}}),c}}function c(e,t,n){var o=s(t,n),r=l.getMethods(e),i={};return Object.keys(r).forEach(function(t){var n=f.getActionName(t,e);i[n]=t}),function(t,n){if(p.verbose("[reducer] reducer of: "+e.constructor.name+", action: "+n.type),void 0===t)return p.verbose("[reducer] state is undefined, returning initial value"),e;if(o!==n.id)return p.verbose("[reducer] component id and action.id don't match ("+o+" !== "+n.id+")"),t;var c=i[n.type],u=r[c];if(!u)return p.verbose("[reducer] no matching action in this reducer, returning previous state"),t;var s=Object.assign({},t);return u.call.apply(u,[s].concat(n.payload)),p.verbose("[reducer] reducer invoked returning new state"),s}}function u(e,t,n){p.verbose("[updateState] updating component in path: ",n.join("."));var o=e,r=l.getProp(t,n),i=[],c=[];p.verbose("[updateState] store before: ",r),p.verbose("[updateState] component before: ",e),Object.keys(r).forEach(function(e){o[e]===r[e]||o[e]instanceof v||(o[e]=r[e],c.push(e))}),Object.keys(e).forEach(function(e){void 0===r[e]&&(delete o[e],i.push(e))}),i.length||c.length?(p.verbose("[updateState] store after: ",r),p.verbose("[updateState] component after: ",e),p.debug("[updateState] state of "+n.join(".")+" changed"),i.length?p.debug("[updateState] props deleted: ",i):p.verbose("[updateState] props deleted: ",i),c.length?p.debug("[updateState] props assigned: ",c):p.verbose("[updateState] props assigned: ",c)):p.verbose("[updateState] no change")}function s(e,t){if(e&&t.length){if(e[d.WITH_ID]){var n=t[t.length-1],o=e[d.WITH_ID][n];if(o){if(o===d.AUTO_ID){var r=--g;return p.verbose("[getComponentId] new component id generated: "+r),e[d.WITH_ID][n]=r,r}return o}}}}Object.defineProperty(t,"__esModule",{value:!0});var a=n(2),p=n(10),f=n(1),l=n(3),d=n(0),v=function(){function e(e,t,n,i){if(!a.isComponentSchema(t))throw new Error("Argument 'schema' is not a component schema. Did you forget to use the decorator?");this[d.DISPOSE]=[],o(this,e,t,n,i),r(this,e,t,i),p.debug("[Component] new "+t.constructor.name+" component created. path: root."+i.join("."))}return e.prototype.disposeComponent=function(){for(var e=this[d.DISPOSE];e.length;){var t=e.pop();t&&t.dispose&&t.dispose()}},e}();t.Component=v;var g=0},function(e,t,n){"use strict";function o(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];i(c.LogLevel.Debug)&&console.log.apply(console,["[ReduxApp] [DEBUG] "+e].concat(t))}function r(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];i(c.LogLevel.Verbose)&&console.log.apply(console,["[ReduxApp] [VERBOSE] "+e].concat(t))}function i(e){return c.globalOptions.logLevel!==c.LogLevel.None&&!(c.globalOptions.logLevel>e)}Object.defineProperty(t,"__esModule",{value:!0});var c=n(1);t.debug=o,t.verbose=r},function(e,t,n){"use strict";function o(e){var t=Object.keys(e);return function(n,o){void 0===n&&(n={});for(var r=!1,i={},c=0,u=t;c<u.length;c++){var s=u[c],a=e[s],p=n[s],f=a(p,o);i[s]=f,r=r||f!==p}return r?i:n}}Object.defineProperty(t,"__esModule",{value:!0}),t.simpleCombineReducers=o},function(e,t,n){"use strict";function o(e){return function(t,n){t[r.WITH_ID]||(t[r.WITH_ID]={}),t[r.WITH_ID][n]=e||r.AUTO_ID}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(0);t.withId=o}])});
{
"name": "redux-app",
"version": "1.0.3",
"version": "1.1.0",
"description": "Type-safe, DRY and OO redux. Implemented with typescript.",
"main": "dist/redux-app.min.js",
"author": "Alon Bar",
"license": "MIT",
"homepage": "https://github.com/alonrbar/redux-app",
"repository": {
"type": "git",
"url": "https://github.com/alonrbar/redux-app.git"
},
"bugs": {
"url": "https://github.com/alonrbar/redux-app/issues"
},
"main": "dist/redux-app.js",
"typings": "dist/index.d.ts",
"scripts": {
"release": "webpack",
"release": "webpack && webpack --config webpack.config.dev.js",
"dev": "webpack --config webpack.config.dev.js --watch",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Alon Bar",
"license": "MIT",
},
"dependencies": {

@@ -26,2 +35,2 @@ "lodash.snakecase": "^4.1.1",

}
}
}

@@ -11,3 +11,3 @@ # redux-app

## Example
## Short Example
```javascript

@@ -44,2 +44,6 @@ @component

## More Examples
More examples can be found here [redux-app-examples](https://github.com/alonrbar/redux-app-examples).
## How it works

@@ -46,0 +50,0 @@

@@ -5,7 +5,5 @@ import { AnyAction, Dispatch, Reducer, Store } from 'redux';

import { getActionName, getSchemaOptions } from './options';
import { getMethods, getProp, getPrototype } from './utils';
import { getMethods, getProp } from './utils';
import { WITH_ID, DISPOSE, REDUCER, AUTO_ID } from './symbols';
export const REDUCER = Symbol('REDUCER');
const DISPOSE = Symbol('DISPOSE');
// TODO: export type IStateListener<T> = (state: T) => void;

@@ -15,3 +13,3 @@

constructor(store: Store<T>, schema: T, path: string[]) {
constructor(store: Store<T>, schema: T, parent: any, path: string[]) {

@@ -23,6 +21,6 @@ if (!isComponentSchema(schema))

createSelf(this, store, schema, path);
createSelf(this, store, schema, parent, path);
createSubComponents(this, store, schema, path);
debug(`[Component] new ${schema.constructor.name} component created. path: ${path.join('.')}`);
debug(`[Component] new ${schema.constructor.name} component created. path: root.${path.join('.')}`);
}

@@ -45,3 +43,3 @@

function createSelf<T>(component: Component<T>, store: Store<T>, schema: T, path: string[]): void {
function createSelf<T>(component: Component<T>, store: Store<T>, schema: T, parent: any, path: string[]): void {

@@ -54,8 +52,7 @@ // regular js props

// actions
const proto = getPrototype(component);
const patchedProto = createActions(store.dispatch, schema);
Object.assign(proto, patchedProto);
const actionInvokers = createActions(store.dispatch, schema, parent, path);
Object.assign(component, actionInvokers);
// reducer
(component as any)[REDUCER] = createReducer(schema);
(component as any)[REDUCER] = createReducer(schema, parent, path);

@@ -74,3 +71,3 @@ // state

if (isComponentSchema(subSchema)) {
(component as any)[key] = new Component(store, subSchema, path.concat([key]));
(component as any)[key] = new Component(store, subSchema, schema, path.concat([key]));
}

@@ -80,3 +77,3 @@ }

function createActions<T>(dispatch: Dispatch<T>, schema: T): any {
function createActions<T>(dispatch: Dispatch<T>, schema: T, parent: any, path: string[]): any {

@@ -87,7 +84,9 @@ var methods = getMethods(schema);

var outputActions: any = {};
var componentId = getComponentId(parent, path);
var actionInvokers: any = {};
Object.keys(methods).forEach(key => {
outputActions[key] = (...payload: any[]): void => {
actionInvokers[key] = (...payload: any[]): void => {
dispatch({
type: getActionName(key, schema),
id: componentId,
payload: payload

@@ -98,7 +97,9 @@ });

return outputActions;
return actionInvokers;
}
function createReducer<T>(schema: T): Reducer<T> {
function createReducer<T>(schema: T, parent: any, path: string[]): Reducer<T> {
var componentId = getComponentId(parent, path);
// method names lookup

@@ -121,2 +122,7 @@ const methods = getMethods(schema);

if (componentId !== action.id) {
verbose(`[reducer] component id and action.id don't match (${componentId} !== ${action.id})`);
return state;
}
// check if should use this reducer

@@ -194,2 +200,33 @@ const methodName = methodNames[action.type];

}
}
var autoComponentId = 0;
function getComponentId(parent: any, path: string[]): any {
// no parent
if (!parent || !path.length)
return undefined;
// withID not used
const idLookup = parent[WITH_ID];
if (!idLookup)
return undefined;
const selfKey = path[path.length - 1];
const id = parent[WITH_ID][selfKey];
// the specific component was not assigned an id
if (!id)
return undefined;
// auto id
if (id === AUTO_ID) {
const generatedId = --autoComponentId;
verbose('[getComponentId] new component id generated: ' + generatedId);
parent[WITH_ID][selfKey] = generatedId;
return generatedId;
}
// manual id
return id;
}

@@ -1,3 +0,4 @@

import { COMPONENT_SCHEMA_OPTIONS, SchemaOptions } from './options';
import { SchemaOptions } from './options';
import { getArgumentNames, getConstructorProp } from './utils';
import { COMPONENT_SCHEMA, COMPONENT_SCHEMA_OPTIONS } from './symbols';

@@ -7,8 +8,2 @@ // tslint:disable:ban-types

//
// symbols
//
const COMPONENT_SCHEMA = Symbol('COMPONENT_SCHEMA');
//
// public

@@ -34,5 +29,5 @@ //

*/
export function assertComponentSchema(obj: any): void {
export function assertComponentSchema(obj: any, msg?: string): void {
if (!isComponentSchema(obj))
throw new Error(`Invalid argument. ${nameof(component)} expected.`);
throw new Error(msg || `Invalid argument. ${nameof(component)} expected.`);
}

@@ -39,0 +34,0 @@

export { component } from './componentSchema';
export { SchemaOptions, GlobalOptions, LogLevel } from './options';
export { ReduxApp } from './reduxApp';
export { ReduxApp } from './reduxApp';
export { withId } from './withId';
import { assertComponentSchema } from './componentSchema';
import { getConstructorProp } from './utils';
import { COMPONENT_SCHEMA_OPTIONS } from './symbols';

@@ -11,4 +12,2 @@ declare var require: any;

export const COMPONENT_SCHEMA_OPTIONS = Symbol('COMPONENT_SCHEMA_OPTIONS');
export class SchemaOptions {

@@ -15,0 +14,0 @@ /**

import { AnyAction, createStore, Reducer, ReducersMapObject, Store, StoreEnhancer } from 'redux';
import { Component, REDUCER } from './component';
import { Component } from './component';
import { globalOptions, GlobalOptions } from './options';
import { simpleCombineReducers } from './reducers';
import { REDUCER } from './symbols';

@@ -31,3 +32,3 @@ export class ReduxApp<T> {

// create the app
const rootComponent = new Component(this.store, appSchema, []);
const rootComponent = new Component(this.store, appSchema, null, []);
this.root = (rootComponent as any);

@@ -34,0 +35,0 @@

@@ -20,3 +20,2 @@ {

"moduleResolution": "node",
"baseUrl": ".",

@@ -23,0 +22,0 @@ // --- validation options --- //

@@ -7,3 +7,3 @@ var path = require('path');

entry: ['./src/index.ts'],
devtool: 'source-map',
devtool: 'sourcemap',
output: {

@@ -10,0 +10,0 @@ path: path.resolve('./dist'),

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc