diff --git a/dist/react-waterfall.dev.js b/dist/react-waterfall.dev.js index d78dcb0..faf0c41 100644 --- a/dist/react-waterfall.dev.js +++ b/dist/react-waterfall.dev.js @@ -1,2 +1,2 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React);function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r=0||(o[r]=e[r]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t1?r-1:0),i=1;i1&&void 0!==arguments[1]?arguments[1]:[],a=React.createContext(),c=new Subscriptions,s=c.getSubscriptions,u=c.subscribe,l=c.unsubscribe,f=r,p=function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i is not initialized yet")}))},{});return{Provider:EnhancedProvider(function(e){var n=_toConsumableArray(i).concat(defaultMiddlewares).map(function(t){return t({initialState:r,actionsCreators:o},e,d)});t={setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:d,subscribe:u,unsubscribe:l}};module.exports=createStore; +"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React);function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r=0||(o[r]=e[r]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t1?r-1:0),i=1;i1&&void 0!==arguments[1]?arguments[1]:[],a=React.createContext(),c=new Subscriptions,s=c.getSubscriptions,u=c.subscribe,l=c.unsubscribe,f=r,p=function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i is not initialized yet")}))},{});return{Provider:EnhancedProvider(function(e){var n=_toConsumableArray(i).concat(defaultMiddlewares).map(function(t){return t({initialState:r,actionsCreators:o},e,d)});t={setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:d,subscribe:u,unsubscribe:l}};module.exports=createStore; //# sourceMappingURL=react-waterfall.dev.js.map diff --git a/dist/react-waterfall.dev.js.map b/dist/react-waterfall.dev.js.map index b29011c..e385421 100644 --- a/dist/react-waterfall.dev.js.map +++ b/dist/react-waterfall.dev.js.map @@ -1 +1 @@ -{"version":3,"file":"react-waterfall.dev.js","sources":["../src/Components/Provider.js","../src/Components/Prevent.js","../src/helpers/connect.js","../src/helpers/subscriptions.js","../src/helpers/devtools.js","../src/index.js"],"sourcesContent":["// @flow\n/* eslint-disable no-undef */\n\nimport React, { Component } from 'react'\n\nimport type { CreateProvider, State } from '../types'\n\ntype Props = { children: React$Node, initialState: {} }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor(props) {\n super()\n this.state = props.initialState || initialState\n setProvider(this)\n }\n\n render() {\n return {this.props.children}\n }\n }\n\nexport default EnhancedProvider\n","// @flow\n/* eslint-disable no-undef */\n\nimport { PureComponent } from 'react'\n\ntype Props = {\n renderComponent: ({}) => React$Node,\n}\n\nexport default class Prevent extends PureComponent {\n render() {\n const { renderComponent, ...rest } = this.props\n return renderComponent(rest)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport * as React from 'react'\nimport Prevent from '../Components/Prevent'\n\nimport type { CreateConnect } from '../types'\n\nconst connect: CreateConnect = Consumer => mapStateToProps => WrappedComponent => {\n const renderComponent = props => \n const ConnectedComponent = props => (\n \n {state => {\n const filteredState = mapStateToProps(state || {})\n return (\n \n )\n }}\n \n )\n\n ConnectedComponent.displayName = `Connect(${WrappedComponent.displayName ||\n WrappedComponent.name ||\n 'Unknown'})`\n\n return ConnectedComponent\n}\n\nexport default connect\n","// @flow\n/* eslint-disable no-undef */\n\nimport type { Subscription } from '../types'\n\nexport default class Subscriptions {\n subscriptions = []\n\n getSubscriptions = () => this.subscriptions\n\n subscribe = (subscription: Subscription) => {\n this.subscriptions = [...this.subscriptions, subscription]\n }\n\n unsubscribe = (subscription: Subscription) => {\n this.subscriptions = this.subscriptions.filter(subscriber => subscriber !== subscription)\n }\n}\n","let id = 0\n\nexport default ({ initialState }, self) => {\n const reduxDevTools = window.devToolsExtension\n\n const instanceID = id\n id += 1\n\n const name = `react-waterfall - ${instanceID}`\n const features = {\n jump: true,\n }\n\n const devTools = reduxDevTools.connect({ name, features })\n\n devTools.subscribe(data => {\n switch (data.type) {\n case 'START':\n devTools.init(initialState)\n break\n case 'RESET':\n self.setState(initialState)\n break\n case 'DISPATCH':\n switch (data.payload.type) {\n case 'JUMP_TO_STATE':\n case 'JUMP_TO_ACTION': {\n self.setState(JSON.parse(data.state))\n break\n }\n default:\n break\n }\n break\n default:\n break\n }\n })\n\n return (action, ...arg) => {\n devTools.send({ type: action, ...arg }, self.state, {}, instanceID)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport { createContext } from 'react'\n\nimport createProvider from './Components/Provider'\nimport createConnect from './helpers/connect'\nimport Subscriptions from './helpers/subscriptions'\nimport devtools from './helpers/devtools'\n\nimport type {\n CreateStore,\n ProviderType,\n SetProvider,\n CustomSetState,\n Context,\n} from './types'\n\nconst defaultMiddlewares =\n process.env.NODE_ENV === 'development' &&\n typeof window !== 'undefined' &&\n window.devToolsExtension\n ? [devtools]\n : []\n\nconst createStore: CreateStore = (\n { initialState, actionsCreators = {} },\n middlewares = [],\n) => {\n let provider: ProviderType\n const context: Context = createContext()\n\n const { getSubscriptions, subscribe, unsubscribe } = new Subscriptions()\n\n const setProvider: SetProvider = self => {\n const initializedMiddlewares = [...middlewares, ...defaultMiddlewares].map(middleware =>\n middleware({ initialState, actionsCreators }, self, actions))\n\n provider = {\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n let state = initialState\n\n const setState: CustomSetState = (action, result, ...args) => {\n state = { ...state, ...result }\n return new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, result, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\n })\n })\n }\n\n const actions = Object.keys(actionsCreators).reduce(\n (r, v) => ({\n ...r,\n [v]: (...args) => {\n if (!provider) {\n console.error(' is not initialized yet')\n return\n }\n\n const result = actionsCreators[v](state, actions, ...args)\n\n return result.then\n ? result.then(result => setState(v, result, ...args))\n : setState(v, result, ...args)\n },\n }),\n {},\n )\n\n const Provider = createProvider(setProvider, context.Provider, initialState)\n const connect = createConnect(context.Consumer)\n\n return {\n Provider,\n connect,\n actions,\n subscribe,\n unsubscribe,\n }\n}\n\nexport default createStore\n"],"names":["EnhancedProvider","setProvider","Provider","initialState","props","state","React","this","children","Component","Prevent","renderComponent","PureComponent","connect","React.createElement","WrappedComponent","ConnectedComponent","Consumer","filteredState","mapStateToProps","displayName","name","Subscriptions","_this","subscriptions","subscription","filter","subscriber","id","self","reduxDevTools","window","devToolsExtension","instanceID","devTools","subscribe","data","type","init","setState","payload","JSON","parse","action","arg","send","defaultMiddlewares","devtools","createStore","provider","actionsCreators","middlewares","context","createContext","getSubscriptions","unsubscribe","result","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","then","error","createProvider","_toConsumableArray","map","middleware","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,iCAGcC,2GAELC,MAAQD,EAAMD,cAAgBA,sHAK5BG,6BAACJ,SAAgBK,KAAKF,OAAQE,KAAKH,MAAMI,gCARrBC,kBCLZC,sMAEoBH,KAAKH,aACnCO,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBX,IACjDY,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBd,cAEpCS,oBAACJ,kCACkBC,GACbP,EACAc,gBAOKE,8BAAyBL,EAAiBK,aAC3DL,EAAiBM,MACjB,eAEKL,KCxBYM,+IAGA,kBAAMC,EAAKC,iDAElB,SAACC,KACND,iCAAoBD,EAAKC,uBAAeC,yCAGjC,SAACA,KACRD,cAAgBD,EAAKC,cAAcE,OAAO,mBAAcC,IAAeF,OCf5EG,GAAK,sBAEyBC,OAAhB1B,IAAAA,aACV2B,EAAgBC,OAAOC,kBAEvBC,EAAaL,OACb,MAEAP,8BAA4BY,GAK5BC,EAAWJ,EAAcjB,gCAHvB,cAKCsB,UAAU,mBACTC,EAAKC,UACN,UACMC,KAAKnC,aAEX,UACEoC,SAASpC,aAEX,kBACKiC,EAAKI,QAAQH,UACd,oBACA,mBACEE,SAASE,KAAKC,MAAMN,EAAK/B,YAYjC,SAACsC,8BAAWC,yDACRC,yBAAaF,GAAWC,GAAOf,EAAKxB,SAAW4B,KCtBtDa,mBAEc,oBAAXf,QACPA,OAAOC,mBACFe,aAGDC,YAA2B,gBAI3BC,EAHF9C,IAAAA,iBAAc+C,gBAAAA,kBAChBC,4DAGMC,EAAmBC,wBAE4B,IAAI/B,cAAjDgC,IAAAA,iBAAkBnB,IAAAA,UAAWoB,IAAAA,YAYjClD,EAAQF,EAENoC,EAA2B,SAACI,EAAQa,8BAAWC,iFACtCpD,EAAUmD,GAChB,IAAIE,QAAQ,YACKJ,IACRK,QAAQ,mBAAMC,gBAAGjB,EAAQa,UAAWC,QACzClB,SAASlC,EAAO,aACdwD,uBAAuBF,QAAQ,mBAAKG,gBAAEnB,UAAWc,eAM1DM,EAAUC,OAAOC,KAAKf,GAAiBgB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFR,OAKCO,EAASN,EAAgBkB,YAAG/D,EAAO0D,UAAYN,WAE9CD,EAAOa,KACVb,EAAOa,KAAK,mBAAU9B,gBAAS6B,EAAGZ,UAAWC,MAC7ClB,gBAAS6B,EAAGZ,UAAWC,YARjBa,MAAM,+DAcLC,iBA3CgB,gBACzBV,EAAyBW,mBAAIrB,UAAgBL,oBAAoB2B,IAAI,mBACzEC,qCAA8C7C,EAAMkC,iBAG1C,SAAC1D,EAAOsE,UAAa9C,EAAKU,SAASlC,EAAOsE,+BAsCXvB,EAAQlD,SAAUC,WAC/CyE,QAAcxB,EAAQnC"} \ No newline at end of file +{"version":3,"file":"react-waterfall.dev.js","sources":["../src/Components/Provider.js","../src/Components/Prevent.js","../src/helpers/connect.js","../src/helpers/subscriptions.js","../src/helpers/devtools.js","../src/index.js"],"sourcesContent":["// @flow\n/* eslint-disable no-undef */\n\nimport React, { Component } from 'react'\n\nimport type { CreateProvider, State } from '../types'\n\ntype Props = { children: React$Node, initialState: {} }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor(props) {\n super(props)\n this.state = props.initialState || initialState\n setProvider(this)\n }\n\n render() {\n return {this.props.children}\n }\n }\n\nexport default EnhancedProvider\n","// @flow\n/* eslint-disable no-undef */\n\nimport { PureComponent } from 'react'\n\ntype Props = {\n renderComponent: ({}) => React$Node,\n}\n\nexport default class Prevent extends PureComponent {\n render() {\n const { renderComponent, ...rest } = this.props\n return renderComponent(rest)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport * as React from 'react'\nimport Prevent from '../Components/Prevent'\n\nimport type { CreateConnect } from '../types'\n\nconst connect: CreateConnect = Consumer => mapStateToProps => WrappedComponent => {\n const renderComponent = props => \n const ConnectedComponent = props => (\n \n {state => {\n const filteredState = mapStateToProps(state || {})\n return (\n \n )\n }}\n \n )\n\n ConnectedComponent.displayName = `Connect(${WrappedComponent.displayName ||\n WrappedComponent.name ||\n 'Unknown'})`\n\n return ConnectedComponent\n}\n\nexport default connect\n","// @flow\n/* eslint-disable no-undef */\n\nimport type { Subscription } from '../types'\n\nexport default class Subscriptions {\n subscriptions = []\n\n getSubscriptions = () => this.subscriptions\n\n subscribe = (subscription: Subscription) => {\n this.subscriptions = [...this.subscriptions, subscription]\n }\n\n unsubscribe = (subscription: Subscription) => {\n this.subscriptions = this.subscriptions.filter(subscriber => subscriber !== subscription)\n }\n}\n","let id = 0\n\nexport default ({ initialState }, self) => {\n const reduxDevTools = window.__REDUX_DEVTOOLS_EXTENSION__\n\n const instanceID = id\n id += 1\n\n const name = `react-waterfall - ${instanceID}`\n const features = {\n jump: true,\n }\n\n const devTools = reduxDevTools.connect({ name, features })\n\n devTools.subscribe(data => {\n switch (data.type) {\n case 'START':\n devTools.init(initialState)\n break\n case 'RESET':\n self.setState(initialState)\n break\n case 'DISPATCH':\n switch (data.payload.type) {\n case 'JUMP_TO_STATE':\n case 'JUMP_TO_ACTION': {\n self.setState(JSON.parse(data.state))\n break\n }\n default:\n break\n }\n break\n default:\n break\n }\n })\n\n return (action, ...arg) => {\n devTools.send({ type: action, ...arg }, self.state, {}, instanceID)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport { createContext } from 'react'\n\nimport createProvider from './Components/Provider'\nimport createConnect from './helpers/connect'\nimport Subscriptions from './helpers/subscriptions'\nimport devtools from './helpers/devtools'\n\nimport type {\n CreateStore,\n ProviderType,\n SetProvider,\n CustomSetState,\n Context,\n} from './types'\n\nconst defaultMiddlewares =\n process.env.NODE_ENV === 'development' &&\n typeof window !== 'undefined' &&\n window.devToolsExtension\n ? [devtools]\n : []\n\nconst createStore: CreateStore = (\n { initialState, actionsCreators = {} },\n middlewares = [],\n) => {\n let provider: ProviderType\n const context: Context = createContext()\n\n const { getSubscriptions, subscribe, unsubscribe } = new Subscriptions()\n\n const setProvider: SetProvider = self => {\n const initializedMiddlewares = [...middlewares, ...defaultMiddlewares].map(middleware =>\n middleware({ initialState, actionsCreators }, self, actions))\n\n provider = {\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n let state = initialState\n\n const setState: CustomSetState = (action, result, ...args) => {\n state = { ...state, ...result }\n return new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, result, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\n })\n })\n }\n\n const actions = Object.keys(actionsCreators).reduce(\n (r, v) => ({\n ...r,\n [v]: (...args) => {\n if (!provider) {\n console.error(' is not initialized yet')\n return\n }\n\n const result = actionsCreators[v](state, actions, ...args)\n\n return result.then\n ? result.then(result => setState(v, result, ...args))\n : setState(v, result, ...args)\n },\n }),\n {},\n )\n\n const Provider = createProvider(setProvider, context.Provider, initialState)\n const connect = createConnect(context.Consumer)\n\n return {\n Provider,\n connect,\n actions,\n subscribe,\n unsubscribe,\n }\n}\n\nexport default createStore\n"],"names":["EnhancedProvider","setProvider","Provider","initialState","props","state","React","this","children","Component","Prevent","renderComponent","PureComponent","connect","React.createElement","WrappedComponent","ConnectedComponent","Consumer","filteredState","mapStateToProps","displayName","name","Subscriptions","_this","subscriptions","subscription","filter","subscriber","id","self","reduxDevTools","window","__REDUX_DEVTOOLS_EXTENSION__","instanceID","devTools","subscribe","data","type","init","setState","payload","JSON","parse","action","arg","send","defaultMiddlewares","devToolsExtension","devtools","createStore","provider","actionsCreators","middlewares","context","createContext","getSubscriptions","unsubscribe","result","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","then","error","createProvider","_toConsumableArray","map","middleware","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,iCAGcC,wGACJA,KACDC,MAAQD,EAAMD,cAAgBA,sHAK5BG,6BAACJ,SAAgBK,KAAKF,OAAQE,KAAKH,MAAMI,gCARrBC,kBCLZC,sMAEoBH,KAAKH,aACnCO,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBX,IACjDY,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBd,cAEpCS,oBAACJ,kCACkBC,GACbP,EACAc,gBAOKE,8BAAyBL,EAAiBK,aAC3DL,EAAiBM,MACjB,eAEKL,KCxBYM,+IAGA,kBAAMC,EAAKC,iDAElB,SAACC,KACND,iCAAoBD,EAAKC,uBAAeC,yCAGjC,SAACA,KACRD,cAAgBD,EAAKC,cAAcE,OAAO,mBAAcC,IAAeF,OCf5EG,GAAK,sBAEyBC,OAAhB1B,IAAAA,aACV2B,EAAgBC,OAAOC,6BAEvBC,EAAaL,OACb,MAEAP,8BAA4BY,GAK5BC,EAAWJ,EAAcjB,gCAHvB,cAKCsB,UAAU,mBACTC,EAAKC,UACN,UACMC,KAAKnC,aAEX,UACEoC,SAASpC,aAEX,kBACKiC,EAAKI,QAAQH,UACd,oBACA,mBACEE,SAASE,KAAKC,MAAMN,EAAK/B,YAYjC,SAACsC,8BAAWC,yDACRC,yBAAaF,GAAWC,GAAOf,EAAKxB,SAAW4B,KCtBtDa,mBAEc,oBAAXf,QACPA,OAAOgB,mBACFC,aAGDC,YAA2B,gBAI3BC,EAHF/C,IAAAA,iBAAcgD,gBAAAA,kBAChBC,4DAGMC,EAAmBC,wBAE4B,IAAIhC,cAAjDiC,IAAAA,iBAAkBpB,IAAAA,UAAWqB,IAAAA,YAYjCnD,EAAQF,EAENoC,EAA2B,SAACI,EAAQc,8BAAWC,iFACtCrD,EAAUoD,GAChB,IAAIE,QAAQ,YACKJ,IACRK,QAAQ,mBAAMC,gBAAGlB,EAAQc,UAAWC,QACzCnB,SAASlC,EAAO,aACdyD,uBAAuBF,QAAQ,mBAAKG,gBAAEpB,UAAWe,eAM1DM,EAAUC,OAAOC,KAAKf,GAAiBgB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFR,OAKCO,EAASN,EAAgBkB,YAAGhE,EAAO2D,UAAYN,WAE9CD,EAAOa,KACVb,EAAOa,KAAK,mBAAU/B,gBAAS8B,EAAGZ,UAAWC,MAC7CnB,gBAAS8B,EAAGZ,UAAWC,YARjBa,MAAM,+DAcLC,iBA3CgB,gBACzBV,EAAyBW,mBAAIrB,UAAgBN,oBAAoB4B,IAAI,mBACzEC,qCAA8C9C,EAAMmC,iBAG1C,SAAC3D,EAAOuE,UAAa/C,EAAKU,SAASlC,EAAOuE,+BAsCXvB,EAAQnD,SAAUC,WAC/C0E,QAAcxB,EAAQpC"} \ No newline at end of file diff --git a/dist/react-waterfall.min.js b/dist/react-waterfall.min.js index d8434d1..b34d598 100644 --- a/dist/react-waterfall.min.js +++ b/dist/react-waterfall.min.js @@ -1,2 +1,2 @@ -"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React);function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r=0||(o[r]=e[r]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t1&&void 0!==arguments[1]?arguments[1]:[],a=React.createContext(),c=new Subscriptions,u=c.getSubscriptions,s=c.subscribe,l=c.unsubscribe,f=r,p=function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i is not initialized yet")}))},{});return{Provider:EnhancedProvider(function(e){var n=_toConsumableArray(i).concat(defaultMiddlewares).map(function(t){return t({initialState:r,actionsCreators:o},e,b)});t={setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:b,subscribe:s,unsubscribe:l}};module.exports=createStore; +"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var React=require("react"),React__default=_interopDefault(React);function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r=0||(o[r]=e[r]);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _possibleConstructorReturn(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?_assertThisInitialized(e):t}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_nonIterableSpread()}function _arrayWithoutHoles(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t1&&void 0!==arguments[1]?arguments[1]:[],a=React.createContext(),c=new Subscriptions,u=c.getSubscriptions,s=c.subscribe,l=c.unsubscribe,f=r,p=function(e,r){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i is not initialized yet")}))},{});return{Provider:EnhancedProvider(function(e){var n=_toConsumableArray(i).concat(defaultMiddlewares).map(function(t){return t({initialState:r,actionsCreators:o},e,b)});t={setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:b,subscribe:s,unsubscribe:l}};module.exports=createStore; //# sourceMappingURL=react-waterfall.min.js.map diff --git a/dist/react-waterfall.min.js.map b/dist/react-waterfall.min.js.map index d9ce0ea..3c66bab 100644 --- a/dist/react-waterfall.min.js.map +++ b/dist/react-waterfall.min.js.map @@ -1 +1 @@ -{"version":3,"file":"react-waterfall.min.js","sources":["../src/Components/Provider.js","../src/Components/Prevent.js","../src/helpers/connect.js","../src/helpers/subscriptions.js","../src/index.js"],"sourcesContent":["// @flow\n/* eslint-disable no-undef */\n\nimport React, { Component } from 'react'\n\nimport type { CreateProvider, State } from '../types'\n\ntype Props = { children: React$Node, initialState: {} }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor(props) {\n super()\n this.state = props.initialState || initialState\n setProvider(this)\n }\n\n render() {\n return {this.props.children}\n }\n }\n\nexport default EnhancedProvider\n","// @flow\n/* eslint-disable no-undef */\n\nimport { PureComponent } from 'react'\n\ntype Props = {\n renderComponent: ({}) => React$Node,\n}\n\nexport default class Prevent extends PureComponent {\n render() {\n const { renderComponent, ...rest } = this.props\n return renderComponent(rest)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport * as React from 'react'\nimport Prevent from '../Components/Prevent'\n\nimport type { CreateConnect } from '../types'\n\nconst connect: CreateConnect = Consumer => mapStateToProps => WrappedComponent => {\n const renderComponent = props => \n const ConnectedComponent = props => (\n \n {state => {\n const filteredState = mapStateToProps(state || {})\n return (\n \n )\n }}\n \n )\n\n ConnectedComponent.displayName = `Connect(${WrappedComponent.displayName ||\n WrappedComponent.name ||\n 'Unknown'})`\n\n return ConnectedComponent\n}\n\nexport default connect\n","// @flow\n/* eslint-disable no-undef */\n\nimport type { Subscription } from '../types'\n\nexport default class Subscriptions {\n subscriptions = []\n\n getSubscriptions = () => this.subscriptions\n\n subscribe = (subscription: Subscription) => {\n this.subscriptions = [...this.subscriptions, subscription]\n }\n\n unsubscribe = (subscription: Subscription) => {\n this.subscriptions = this.subscriptions.filter(subscriber => subscriber !== subscription)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport { createContext } from 'react'\n\nimport createProvider from './Components/Provider'\nimport createConnect from './helpers/connect'\nimport Subscriptions from './helpers/subscriptions'\nimport devtools from './helpers/devtools'\n\nimport type {\n CreateStore,\n ProviderType,\n SetProvider,\n CustomSetState,\n Context,\n} from './types'\n\nconst defaultMiddlewares =\n process.env.NODE_ENV === 'development' &&\n typeof window !== 'undefined' &&\n window.devToolsExtension\n ? [devtools]\n : []\n\nconst createStore: CreateStore = (\n { initialState, actionsCreators = {} },\n middlewares = [],\n) => {\n let provider: ProviderType\n const context: Context = createContext()\n\n const { getSubscriptions, subscribe, unsubscribe } = new Subscriptions()\n\n const setProvider: SetProvider = self => {\n const initializedMiddlewares = [...middlewares, ...defaultMiddlewares].map(middleware =>\n middleware({ initialState, actionsCreators }, self, actions))\n\n provider = {\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n let state = initialState\n\n const setState: CustomSetState = (action, result, ...args) => {\n state = { ...state, ...result }\n return new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, result, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\n })\n })\n }\n\n const actions = Object.keys(actionsCreators).reduce(\n (r, v) => ({\n ...r,\n [v]: (...args) => {\n if (!provider) {\n console.error(' is not initialized yet')\n return\n }\n\n const result = actionsCreators[v](state, actions, ...args)\n\n return result.then\n ? result.then(result => setState(v, result, ...args))\n : setState(v, result, ...args)\n },\n }),\n {},\n )\n\n const Provider = createProvider(setProvider, context.Provider, initialState)\n const connect = createConnect(context.Consumer)\n\n return {\n Provider,\n connect,\n actions,\n subscribe,\n unsubscribe,\n }\n}\n\nexport default createStore\n"],"names":["EnhancedProvider","setProvider","Provider","initialState","props","state","React","this","children","Component","Prevent","renderComponent","PureComponent","connect","React.createElement","WrappedComponent","ConnectedComponent","Consumer","filteredState","mapStateToProps","displayName","name","Subscriptions","_this","subscriptions","subscription","filter","subscriber","defaultMiddlewares","createStore","provider","actionsCreators","middlewares","context","createContext","getSubscriptions","subscribe","unsubscribe","setState","action","result","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","then","error","createProvider","_toConsumableArray","map","middleware","self","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,iCAGcC,2GAELC,MAAQD,EAAMD,cAAgBA,sHAK5BG,6BAACJ,SAAgBK,KAAKF,OAAQE,KAAKH,MAAMI,gCARrBC,kBCLZC,sMAEoBH,KAAKH,aACnCO,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBX,IACjDY,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBd,cAEpCS,oBAACJ,kCACkBC,GACbP,EACAc,gBAOKE,8BAAyBL,EAAiBK,aAC3DL,EAAiBM,MACjB,eAEKL,KCxBYM,+IAGA,kBAAMC,EAAKC,iDAElB,SAACC,KACND,iCAAoBD,EAAKC,uBAAeC,yCAGjC,SAACA,KACRD,cAAgBD,EAAKC,cAAcE,OAAO,mBAAcC,IAAeF,OCG1EG,sBAOAC,YAA2B,gBAI3BC,EAHF3B,IAAAA,iBAAc4B,gBAAAA,kBAChBC,4DAGMC,EAAmBC,wBAE4B,IAAIZ,cAAjDa,IAAAA,iBAAkBC,IAAAA,UAAWC,IAAAA,YAYjChC,EAAQF,EAENmC,EAA2B,SAACC,EAAQC,8BAAWC,iFACtCpC,EAAUmC,GAChB,IAAIE,QAAQ,YACKP,IACRQ,QAAQ,mBAAMC,gBAAGL,EAAQC,UAAWC,QACzCH,SAASjC,EAAO,aACdwC,uBAAuBF,QAAQ,mBAAKG,gBAAEP,UAAWE,eAM1DM,EAAUC,OAAOC,KAAKlB,GAAiBmB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFX,OAKCU,EAAST,EAAgBqB,YAAG/C,EAAO0C,UAAYN,WAE9CD,EAAOa,KACVb,EAAOa,KAAK,mBAAUf,gBAASc,EAAGZ,UAAWC,MAC7CH,gBAASc,EAAGZ,UAAWC,YARjBa,MAAM,+DAcLC,iBA3CgB,gBACzBV,EAAyBW,mBAAIxB,UAAgBJ,oBAAoB6B,IAAI,mBACzEC,qCAA8CC,EAAMZ,iBAG1C,SAAC1C,EAAOuD,UAAaD,EAAKrB,SAASjC,EAAOuD,+BAsCX3B,EAAQ/B,SAAUC,WAC/C0D,QAAc5B,EAAQhB"} \ No newline at end of file +{"version":3,"file":"react-waterfall.min.js","sources":["../src/Components/Provider.js","../src/Components/Prevent.js","../src/helpers/connect.js","../src/helpers/subscriptions.js","../src/index.js"],"sourcesContent":["// @flow\n/* eslint-disable no-undef */\n\nimport React, { Component } from 'react'\n\nimport type { CreateProvider, State } from '../types'\n\ntype Props = { children: React$Node, initialState: {} }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor(props) {\n super(props)\n this.state = props.initialState || initialState\n setProvider(this)\n }\n\n render() {\n return {this.props.children}\n }\n }\n\nexport default EnhancedProvider\n","// @flow\n/* eslint-disable no-undef */\n\nimport { PureComponent } from 'react'\n\ntype Props = {\n renderComponent: ({}) => React$Node,\n}\n\nexport default class Prevent extends PureComponent {\n render() {\n const { renderComponent, ...rest } = this.props\n return renderComponent(rest)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport * as React from 'react'\nimport Prevent from '../Components/Prevent'\n\nimport type { CreateConnect } from '../types'\n\nconst connect: CreateConnect = Consumer => mapStateToProps => WrappedComponent => {\n const renderComponent = props => \n const ConnectedComponent = props => (\n \n {state => {\n const filteredState = mapStateToProps(state || {})\n return (\n \n )\n }}\n \n )\n\n ConnectedComponent.displayName = `Connect(${WrappedComponent.displayName ||\n WrappedComponent.name ||\n 'Unknown'})`\n\n return ConnectedComponent\n}\n\nexport default connect\n","// @flow\n/* eslint-disable no-undef */\n\nimport type { Subscription } from '../types'\n\nexport default class Subscriptions {\n subscriptions = []\n\n getSubscriptions = () => this.subscriptions\n\n subscribe = (subscription: Subscription) => {\n this.subscriptions = [...this.subscriptions, subscription]\n }\n\n unsubscribe = (subscription: Subscription) => {\n this.subscriptions = this.subscriptions.filter(subscriber => subscriber !== subscription)\n }\n}\n","// @flow\n/* eslint-disable no-undef */\n\nimport { createContext } from 'react'\n\nimport createProvider from './Components/Provider'\nimport createConnect from './helpers/connect'\nimport Subscriptions from './helpers/subscriptions'\nimport devtools from './helpers/devtools'\n\nimport type {\n CreateStore,\n ProviderType,\n SetProvider,\n CustomSetState,\n Context,\n} from './types'\n\nconst defaultMiddlewares =\n process.env.NODE_ENV === 'development' &&\n typeof window !== 'undefined' &&\n window.devToolsExtension\n ? [devtools]\n : []\n\nconst createStore: CreateStore = (\n { initialState, actionsCreators = {} },\n middlewares = [],\n) => {\n let provider: ProviderType\n const context: Context = createContext()\n\n const { getSubscriptions, subscribe, unsubscribe } = new Subscriptions()\n\n const setProvider: SetProvider = self => {\n const initializedMiddlewares = [...middlewares, ...defaultMiddlewares].map(middleware =>\n middleware({ initialState, actionsCreators }, self, actions))\n\n provider = {\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n let state = initialState\n\n const setState: CustomSetState = (action, result, ...args) => {\n state = { ...state, ...result }\n return new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, result, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\n })\n })\n }\n\n const actions = Object.keys(actionsCreators).reduce(\n (r, v) => ({\n ...r,\n [v]: (...args) => {\n if (!provider) {\n console.error(' is not initialized yet')\n return\n }\n\n const result = actionsCreators[v](state, actions, ...args)\n\n return result.then\n ? result.then(result => setState(v, result, ...args))\n : setState(v, result, ...args)\n },\n }),\n {},\n )\n\n const Provider = createProvider(setProvider, context.Provider, initialState)\n const connect = createConnect(context.Consumer)\n\n return {\n Provider,\n connect,\n actions,\n subscribe,\n unsubscribe,\n }\n}\n\nexport default createStore\n"],"names":["EnhancedProvider","setProvider","Provider","initialState","props","state","React","this","children","Component","Prevent","renderComponent","PureComponent","connect","React.createElement","WrappedComponent","ConnectedComponent","Consumer","filteredState","mapStateToProps","displayName","name","Subscriptions","_this","subscriptions","subscription","filter","subscriber","defaultMiddlewares","createStore","provider","actionsCreators","middlewares","context","createContext","getSubscriptions","subscribe","unsubscribe","setState","action","result","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","then","error","createProvider","_toConsumableArray","map","middleware","self","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,iCAGcC,wGACJA,KACDC,MAAQD,EAAMD,cAAgBA,sHAK5BG,6BAACJ,SAAgBK,KAAKF,OAAQE,KAAKH,MAAMI,gCARrBC,kBCLZC,sMAEoBH,KAAKH,aACnCO,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBX,IACjDY,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBd,cAEpCS,oBAACJ,kCACkBC,GACbP,EACAc,gBAOKE,8BAAyBL,EAAiBK,aAC3DL,EAAiBM,MACjB,eAEKL,KCxBYM,+IAGA,kBAAMC,EAAKC,iDAElB,SAACC,KACND,iCAAoBD,EAAKC,uBAAeC,yCAGjC,SAACA,KACRD,cAAgBD,EAAKC,cAAcE,OAAO,mBAAcC,IAAeF,OCG1EG,sBAOAC,YAA2B,gBAI3BC,EAHF3B,IAAAA,iBAAc4B,gBAAAA,kBAChBC,4DAGMC,EAAmBC,wBAE4B,IAAIZ,cAAjDa,IAAAA,iBAAkBC,IAAAA,UAAWC,IAAAA,YAYjChC,EAAQF,EAENmC,EAA2B,SAACC,EAAQC,8BAAWC,iFACtCpC,EAAUmC,GAChB,IAAIE,QAAQ,YACKP,IACRQ,QAAQ,mBAAMC,gBAAGL,EAAQC,UAAWC,QACzCH,SAASjC,EAAO,aACdwC,uBAAuBF,QAAQ,mBAAKG,gBAAEP,UAAWE,eAM1DM,EAAUC,OAAOC,KAAKlB,GAAiBmB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFX,OAKCU,EAAST,EAAgBqB,YAAG/C,EAAO0C,UAAYN,WAE9CD,EAAOa,KACVb,EAAOa,KAAK,mBAAUf,gBAASc,EAAGZ,UAAWC,MAC7CH,gBAASc,EAAGZ,UAAWC,YARjBa,MAAM,+DAcLC,iBA3CgB,gBACzBV,EAAyBW,mBAAIxB,UAAgBJ,oBAAoB6B,IAAI,mBACzEC,qCAA8CC,EAAMZ,iBAG1C,SAAC1C,EAAOuD,UAAaD,EAAKrB,SAASjC,EAAOuD,+BAsCX3B,EAAQ/B,SAAUC,WAC/C0D,QAAc5B,EAAQhB"} \ No newline at end of file diff --git a/package.json b/package.json index fe5c2c1..6cc5409 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-waterfall", - "version": "4.0.0", + "version": "4.0.1", "description": "", "main": "index.js", "files": [