diff --git a/dist/react-waterfall.dev.js b/dist/react-waterfall.dev.js index a7ee818..520ec68 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,f=c.unsubscribe,l=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,p)});t={getState:function(){return e.state},setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:p,subscribe:u,unsubscribe:f}};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=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,p)});t={getState:function(){return e.state},setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:p,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 cb9bb69..bea8dc7 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 }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor() {\n super()\n this.state = 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 getState: () => self.state,\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n const setState: CustomSetState = (action, state, ...args) =>\n new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, state, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\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 const result = actionsCreators[v](provider.getState(), ...args)\n\n return result.then\n ? result.then(res => setState(v, res, ...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","state","React","this","props","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","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","result","getState","then","res","error","createProvider","_toConsumableArray","map","middleware","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,2IAKSC,MAAQD,sHAKNE,6BAACH,SAAgBI,KAAKF,OAAQE,KAAKC,MAAMC,gCARrBC,kBCLZC,sMAEoBJ,KAAKC,aACnCI,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBR,IACjDS,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBf,cAEpCU,oBAACJ,kCACkBC,GACbJ,EACAW,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,EAAKhC,YAYjC,SAACuC,8BAAWC,yDACRC,yBAAaF,GAAWC,GAAOf,EAAKzB,SAAW6B,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,YAa/BhB,EAA2B,SAACI,EAAQvC,8BAAUoD,8DAClD,IAAIC,QAAQ,YACYH,IACRI,QAAQ,mBAAMC,gBAAGhB,EAAQvC,UAAUoD,QACxCjB,SAASnC,EAAO,aACdwD,uBAAuBF,QAAQ,mBAAKG,gBAAElB,UAAWa,eAK1DM,EAAUC,OAAOC,KAAKd,GAAiBe,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFP,OAICmB,EAASlB,EAAgBiB,YAAGlB,EAASoB,mBAAeb,WAEnDY,EAAOE,KACVF,EAAOE,KAAK,mBAAO/B,gBAAS4B,EAAGI,UAAQf,MACvCjB,gBAAS4B,EAAGC,UAAWZ,YAPjBgB,MAAM,+DAaLC,iBAvCgB,gBACzBb,EAAyBc,mBAAIvB,UAAgBL,oBAAoB6B,IAAI,mBACzEC,qCAA8C/C,EAAMiC,iBAG1C,kBAAMjC,EAAKzB,gBACX,SAACA,EAAOyE,UAAahD,EAAKU,SAASnC,EAAOyE,+BAiCXzB,EAAQlD,SAAUC,WAC/C2E,QAAc1B,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()\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 getState: () => self.state,\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n const setState: CustomSetState = (action, state, ...args) =>\n new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, state, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\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 const result = actionsCreators[v](provider.getState(), ...args)\n\n return result.then\n ? result.then(res => setState(v, res, ...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","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","result","getState","then","res","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,YAa/BhB,EAA2B,SAACI,EAAQtC,8BAAUmD,8DAClD,IAAIC,QAAQ,YACYH,IACRI,QAAQ,mBAAMC,gBAAGhB,EAAQtC,UAAUmD,QACxCjB,SAASlC,EAAO,aACduD,uBAAuBF,QAAQ,mBAAKG,gBAAElB,UAAWa,eAK1DM,EAAUC,OAAOC,KAAKd,GAAiBe,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFP,OAICmB,EAASlB,EAAgBiB,YAAGlB,EAASoB,mBAAeb,WAEnDY,EAAOE,KACVF,EAAOE,KAAK,mBAAO/B,gBAAS4B,EAAGI,UAAQf,MACvCjB,gBAAS4B,EAAGC,UAAWZ,YAPjBgB,MAAM,+DAaLC,iBAvCgB,gBACzBb,EAAyBc,mBAAIvB,UAAgBL,oBAAoB6B,IAAI,mBACzEC,qCAA8C/C,EAAMiC,iBAG1C,kBAAMjC,EAAKxB,gBACX,SAACA,EAAOwE,UAAahD,EAAKU,SAASlC,EAAOwE,+BAiCXzB,EAAQlD,SAAUC,WAC/C2E,QAAc1B,EAAQnC"} \ No newline at end of file diff --git a/dist/react-waterfall.min.js b/dist/react-waterfall.min.js index 527a601..a71ae81 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,f=c.unsubscribe,l=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,p)});t={getState:function(){return e.state},setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:p,subscribe:s,unsubscribe:f}};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,f=c.unsubscribe,l=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,p)});t={getState:function(){return e.state},setState:function(t,r){return e.setState(t,r)},initializedMiddlewares:n}},a.Provider,r),connect:connect(a.Consumer),actions:p,subscribe:s,unsubscribe:f}};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 ae94bf4..19b14c1 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 }\n\nconst EnhancedProvider: CreateProvider = (\n setProvider,\n Provider,\n initialState,\n) =>\n class EnhancedProvider extends Component {\n constructor() {\n super()\n this.state = 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 getState: () => self.state,\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n const setState: CustomSetState = (action, state, ...args) =>\n new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, state, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\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 const result = actionsCreators[v](provider.getState(), ...args)\n\n return result.then\n ? result.then(res => setState(v, res, ...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","state","React","this","props","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","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","result","getState","then","res","error","createProvider","_toConsumableArray","map","middleware","self","callback","createConnect"],"mappings":"gsFASA,IAAMA,iBAAmC,SACvCC,EACAC,EACAC,2IAKSC,MAAQD,sHAKNE,6BAACH,SAAgBI,KAAKF,OAAQE,KAAKC,MAAMC,gCARrBC,kBCLZC,sMAEoBJ,KAAKC,aACnCI,IADCA,wFAFyBC,qBCD/BC,QAAyB,mBAAY,mBAAmB,gBACtDF,EAAkB,mBAASG,oBAACC,EAAqBR,IACjDS,EAAqB,mBACzBF,oBAACG,OACE,gBACOC,EAAgBC,EAAgBf,cAEpCU,oBAACJ,kCACkBC,GACbJ,EACAW,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,YAa/BC,EAA2B,SAACC,EAAQnC,8BAAUoC,8DAClD,IAAIC,QAAQ,YACYN,IACRO,QAAQ,mBAAMC,gBAAGJ,EAAQnC,UAAUoC,QACxCF,SAASlC,EAAO,aACdwC,uBAAuBF,QAAQ,mBAAKG,gBAAEN,UAAWC,eAK1DM,EAAUC,OAAOC,KAAKjB,GAAiBkB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFV,OAICsB,EAASrB,EAAgBoB,YAAGrB,EAASuB,mBAAeb,WAEnDY,EAAOE,KACVF,EAAOE,KAAK,mBAAOhB,gBAASa,EAAGI,UAAQf,MACvCF,gBAASa,EAAGC,UAAWZ,YAPjBgB,MAAM,+DAaLC,iBAvCgB,gBACzBb,EAAyBc,mBAAI1B,UAAgBJ,oBAAoB+B,IAAI,mBACzEC,qCAA8CC,EAAMf,iBAG1C,kBAAMe,EAAKzD,gBACX,SAACA,EAAO0D,UAAaD,EAAKvB,SAASlC,EAAO0D,+BAiCX7B,EAAQ/B,SAAUC,WAC/C4D,QAAc9B,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()\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 getState: () => self.state,\n setState: (state, callback) => self.setState(state, callback),\n initializedMiddlewares,\n }\n }\n\n const setState: CustomSetState = (action, state, ...args) =>\n new Promise(resolve => {\n const subscriptions = getSubscriptions()\n subscriptions.forEach(fn => fn(action, state, ...args))\n provider.setState(state, () => {\n provider.initializedMiddlewares.forEach(m => m(action, ...args))\n resolve()\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 const result = actionsCreators[v](provider.getState(), ...args)\n\n return result.then\n ? result.then(res => setState(v, res, ...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","args","Promise","forEach","fn","initializedMiddlewares","m","actions","Object","keys","reduce","r","v","result","getState","then","res","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,YAa/BC,EAA2B,SAACC,EAAQlC,8BAAUmC,8DAClD,IAAIC,QAAQ,YACYN,IACRO,QAAQ,mBAAMC,gBAAGJ,EAAQlC,UAAUmC,QACxCF,SAASjC,EAAO,aACduC,uBAAuBF,QAAQ,mBAAKG,gBAAEN,UAAWC,eAK1DM,EAAUC,OAAOC,KAAKjB,GAAiBkB,OAC3C,SAACC,EAAGC,2BACCD,qBACFC,EAAI,sCAAIX,gDACFV,OAICsB,EAASrB,EAAgBoB,YAAGrB,EAASuB,mBAAeb,WAEnDY,EAAOE,KACVF,EAAOE,KAAK,mBAAOhB,gBAASa,EAAGI,UAAQf,MACvCF,gBAASa,EAAGC,UAAWZ,YAPjBgB,MAAM,+DAaLC,iBAvCgB,gBACzBb,EAAyBc,mBAAI1B,UAAgBJ,oBAAoB+B,IAAI,mBACzEC,qCAA8CC,EAAMf,iBAG1C,kBAAMe,EAAKxD,gBACX,SAACA,EAAOyD,UAAaD,EAAKvB,SAASjC,EAAOyD,+BAiCX7B,EAAQ/B,SAAUC,WAC/C4D,QAAc9B,EAAQhB"} \ No newline at end of file diff --git a/package.json b/package.json index e2bddfa..b66f58c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-waterfall", - "version": "4.0.0-beta.1", + "version": "4.0.0-beta.2", "description": "", "main": "index.js", "files": ["index.js", "package.json", "README.md", "dist/"], diff --git a/src/Components/Provider.js b/src/Components/Provider.js index 12b0388..6ee6bd9 100644 --- a/src/Components/Provider.js +++ b/src/Components/Provider.js @@ -5,7 +5,7 @@ import React, { Component } from 'react' import type { CreateProvider, State } from '../types' -type Props = { children: React$Node } +type Props = { children: React$Node, initialState: {} } const EnhancedProvider: CreateProvider = ( setProvider, @@ -13,9 +13,9 @@ const EnhancedProvider: CreateProvider = ( initialState, ) => class EnhancedProvider extends Component { - constructor() { + constructor(props) { super() - this.state = initialState + this.state = props.initialState || initialState setProvider(this) }