redux-zero
Advanced tools
Comparing version 4.5.2 to 4.6.0
# Changelog | ||
### 4.6.0 | ||
- Adds middleware support: | ||
```js | ||
// a middleware | ||
const logger = (store) => (next) => (action) => { | ||
console.log('current state', store.getState()) | ||
return next(action); | ||
} | ||
// compose middlewares | ||
const middlewares = applyMiddleware( | ||
logger, | ||
anotherMiddleware | ||
); | ||
const store = createStore({}, middlewares); | ||
``` | ||
### 4.5.2 | ||
@@ -4,0 +24,0 @@ |
@@ -29,6 +29,8 @@ 'use strict'; | ||
function createStore$1(state) { | ||
function createStore$1(state, middleware) { | ||
if (state === void 0) { state = {}; } | ||
if (middleware === void 0) { middleware = null; } | ||
var listeners = []; | ||
return { | ||
middleware: middleware, | ||
setState: function (update) { | ||
@@ -35,0 +37,0 @@ state = |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):t["redux-zero"]=e()}(this,function(){"use strict";var t=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t};return function(e){void 0===e&&(e={});var n=[];return{setState:function(o){e="function"==typeof o?t({},e,o(e)):t({},e,o),n.forEach(function(t){return t(e)})},subscribe:function(t){return n.push(t),function(){n.splice(n.indexOf(t),1)}},getState:function(){return e}}}}); | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):e["redux-zero"]=n()}(this,function(){"use strict";var e=Object.assign||function(e){for(var n,t=1,o=arguments.length;t<o;t++){n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e};return function(n,t){void 0===n&&(n={}),void 0===t&&(t=null);var o=[];return{middleware:t,setState:function(t){n="function"==typeof t?e({},n,t(n)):e({},n,t),o.forEach(function(e){return e(n)})},subscribe:function(e){return o.push(e),function(){o.splice(o.indexOf(e),1)}},getState:function(){return n}}}}); | ||
//# sourceMappingURL=redux-zero.min.js.map |
export default interface Store { | ||
middleware: Function; | ||
setState: Function; | ||
@@ -3,0 +4,0 @@ subscribe: Function; |
{ | ||
"name": "redux-zero", | ||
"version": "4.5.2", | ||
"version": "4.6.0", | ||
"description": "", | ||
@@ -9,4 +9,6 @@ "main": "dist/redux-zero.js", | ||
"compile": "tsc --pretty", | ||
"compile:watch": "tsc --pretty --watch", | ||
"lint": "tslint src/**/*.ts src/**/*.tsx", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"format": "prettier --write --no-semi \"src/**/*.ts\" \"src/**/*.tsx\"", | ||
@@ -13,0 +15,0 @@ "check": |
@@ -51,2 +51,10 @@ 'use strict'; | ||
function set(store, ret) { | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
} | ||
} | ||
function bindActions(actions, store) { | ||
@@ -61,8 +69,7 @@ actions = typeof actions === "function" ? actions(store) : actions; | ||
} | ||
var ret = actions[name_1].apply(actions, [store.getState()].concat(args)); | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
var action = actions[name_1]; | ||
if (typeof store.middleware === "function") { | ||
return store.middleware(store, action, args); | ||
} | ||
return set(store, action.apply(void 0, [store.getState()].concat(args))); | ||
}; | ||
@@ -69,0 +76,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],e):e(t["redux-zero"]={},t.preact)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function o(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function r(t,e){t="function"==typeof t?t(e):t;var n={};for(var o in t)!function(o){n[o]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var i=t[o].apply(t,[e.getState()].concat(n));if(null!=i){if(i.then)return i.then(e.setState);e.setState(i)}}}(o);return n}var i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},p=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},s=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state=e.getProps(),e.actions=e.getActions(),e.update=function(){var t=e.getProps();o(t,e.state)||e.setState(t)},e}return n(e,t),e.prototype.componentWillMount=function(){this.unsubscribe=this.context.store.subscribe(this.update)},e.prototype.componentWillUnmount=function(){this.unsubscribe(this.update)},e.prototype.getProps=function(){var t=this.props.mapToProps,e=this.context.store&&this.context.store.getState()||{};return t?t(e,this.props):e},e.prototype.getActions=function(){return r(this.props.actions,this.context.store)},e.prototype.render=function(t,e,n){var o=t.children,r=n.store;return o[0](p({store:r},e,this.actions))},e}(e.Component),u=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.getChildContext=function(){return{store:this.props.store}},e.prototype.render=function(){return this.props.children[0]},e}(e.Component);t.Provider=u,t.Connect=s,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("preact")):"function"==typeof define&&define.amd?define(["exports","preact"],e):e(t["redux-zero"]={},t.preact)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}p(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function o(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function r(t,e){if(null!=e){if(e.then)return e.then(t.setState);t.setState(e)}}function i(t,e){t="function"==typeof t?t(e):t;var n={};for(var o in t)!function(o){n[o]=function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var p=t[o];return"function"==typeof e.middleware?e.middleware(e,p,n):r(e,p.apply(void 0,[e.getState()].concat(n)))}}(o);return n}var p=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},s=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},u=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state=e.getProps(),e.actions=e.getActions(),e.update=function(){var t=e.getProps();o(t,e.state)||e.setState(t)},e}return n(e,t),e.prototype.componentWillMount=function(){this.unsubscribe=this.context.store.subscribe(this.update)},e.prototype.componentWillUnmount=function(){this.unsubscribe(this.update)},e.prototype.getProps=function(){var t=this.props.mapToProps,e=this.context.store&&this.context.store.getState()||{};return t?t(e,this.props):e},e.prototype.getActions=function(){return i(this.props.actions,this.context.store)},e.prototype.render=function(t,e,n){var o=t.children,r=n.store;return o[0](s({store:r},e,this.actions))},e}(e.Component),c=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return n(e,t),e.prototype.getChildContext=function(){return{store:this.props.store}},e.prototype.render=function(){return this.props.children[0]},e}(e.Component);t.Provider=c,t.Connect=u,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -58,2 +58,10 @@ 'use strict'; | ||
function set(store, ret) { | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
} | ||
} | ||
function bindActions(actions, store) { | ||
@@ -68,8 +76,7 @@ actions = typeof actions === "function" ? actions(store) : actions; | ||
} | ||
var ret = actions[name_1].apply(actions, [store.getState()].concat(args)); | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
var action = actions[name_1]; | ||
if (typeof store.middleware === "function") { | ||
return store.middleware(store, action, args); | ||
} | ||
return set(store, action.apply(void 0, [store.getState()].concat(args))); | ||
}; | ||
@@ -76,0 +83,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t["redux-zero"]={},t.React)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function o(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function r(t,e,n){return"object"==typeof t?null:new Error("Invalid prop "+e+" supplied to "+n)}function i(t,e){t="function"==typeof t?t(e):t;var n={};for(var o in t)!function(o){n[o]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var i=t[o].apply(t,[e.getState()].concat(n));if(null!=i){if(i.then)return i.then(e.setState);e.setState(i)}}}(o);return n}var s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},p=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},u=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state=e.getProps(),e.actions=e.getActions(),e.update=function(){var t=e.getProps();o(t,e.state)||e.setState(t)},e}return n(e,t),e.prototype.componentWillMount=function(){this.unsubscribe=this.context.store.subscribe(this.update)},e.prototype.componentWillUnmount=function(){this.unsubscribe(this.update)},e.prototype.getProps=function(){var t=this.props.mapToProps,e=this.context.store&&this.context.store.getState()||{};return t?t(e,this.props):e},e.prototype.getActions=function(){return i(this.props.actions,this.context.store)},e.prototype.render=function(){return this.props.children(p({store:this.context.store},this.state,this.actions))},e.contextTypes={store:r},e}(e.Component),c=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return n(o,t),o.prototype.getChildContext=function(){return{store:this.props.store}},o.prototype.render=function(){var t=this.props.children;return e.Children.only(t)},o.childContextTypes={store:r},o}(e.Component);t.connect=function(t,n){return void 0===n&&(n={}),function(o){return function(r){return e.createElement(u,p({},r,{mapToProps:t,actions:n}),function(t){return e.createElement(o,p({},t,r))})}}},t.Provider=c,t.Connect=u,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],e):e(t["redux-zero"]={},t.React)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}u(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function o(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function r(t,e,n){return"object"==typeof t?null:new Error("Invalid prop "+e+" supplied to "+n)}function i(t,e){if(null!=e){if(e.then)return e.then(t.setState);t.setState(e)}}function s(t,e){t="function"==typeof t?t(e):t;var n={};for(var o in t)!function(o){n[o]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var s=t[o];return"function"==typeof e.middleware?e.middleware(e,s,n):i(e,s.apply(void 0,[e.getState()].concat(n)))}}(o);return n}var u=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},c=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++){e=arguments[n];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r])}return t},p=function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.state=e.getProps(),e.actions=e.getActions(),e.update=function(){var t=e.getProps();o(t,e.state)||e.setState(t)},e}return n(e,t),e.prototype.componentWillMount=function(){this.unsubscribe=this.context.store.subscribe(this.update)},e.prototype.componentWillUnmount=function(){this.unsubscribe(this.update)},e.prototype.getProps=function(){var t=this.props.mapToProps,e=this.context.store&&this.context.store.getState()||{};return t?t(e,this.props):e},e.prototype.getActions=function(){return s(this.props.actions,this.context.store)},e.prototype.render=function(){return this.props.children(c({store:this.context.store},this.state,this.actions))},e.contextTypes={store:r},e}(e.Component),f=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return n(o,t),o.prototype.getChildContext=function(){return{store:this.props.store}},o.prototype.render=function(){var t=this.props.children;return e.Children.only(t)},o.childContextTypes={store:r},o}(e.Component);t.connect=function(t,n){return void 0===n&&(n={}),function(o){return function(r){return e.createElement(p,c({},r,{mapToProps:t,actions:n}),function(t){return e.createElement(o,c({},t,r))})}}},t.Provider=f,t.Connect=p,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -23,2 +23,3 @@ <h1 align="center"> | ||
- [Example](#example) | ||
- [Middleware](#middleware) | ||
- [Inspiration](#inspiration) | ||
@@ -151,2 +152,29 @@ - [Roadmap](#roadmap) | ||
## Middleware | ||
There is basic middleware support as of 4.6.0. The method signature for the middleware was inspired by redux. The main difference is that action is a function. | ||
eg: | ||
```js | ||
/* store.js */ | ||
import createStore from "redux-zero"; | ||
import { applyMiddleware } from "redux-zero/middleware" | ||
const logger = (store) => (next) => (action) => { | ||
console.log('current state', store.getState()) | ||
return next(action); | ||
} | ||
const initialState = { count: 1 }; | ||
const middlewares = applyMiddleware( | ||
logger, | ||
anotherMiddleware | ||
); | ||
const store = createStore(initialState, middlewares); | ||
export default store; | ||
``` | ||
## Inspiration | ||
@@ -157,3 +185,2 @@ **Redux Zero** was based on this [gist](https://gist.github.com/developit/55c48d294abab13a146eac236bae3219) by [@developit](https://github.com/developit) | ||
- Add more examples (including unit tests, SSR, etc) | ||
- Add middleware | ||
@@ -160,0 +187,0 @@ ## Tools |
import Store from "../interfaces/Store"; | ||
export default function createStore(state?: {}): Store; | ||
export default function createStore(state?: {}, middleware?: any): Store; |
@@ -68,2 +68,10 @@ 'use strict'; | ||
function set(store, ret) { | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
} | ||
} | ||
function bindActions(actions, store) { | ||
@@ -78,8 +86,7 @@ actions = typeof actions === "function" ? actions(store) : actions; | ||
} | ||
var ret = actions[name_1].apply(actions, [store.getState()].concat(args)); | ||
if (ret != null) { | ||
if (ret.then) | ||
return ret.then(store.setState); | ||
store.setState(ret); | ||
var action = actions[name_1]; | ||
if (typeof store.middleware === "function") { | ||
return store.middleware(store, action, args); | ||
} | ||
return set(store, action.apply(void 0, [store.getState()].concat(args))); | ||
}; | ||
@@ -86,0 +93,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t["redux-zero"]={})}(this,function(t){"use strict";function e(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function n(t,n){return t!==n||!(!t||"object"!=typeof t)&&!e(t,n)}function r(t,e){var r={},o=!1;for(var i in t){var c=t[i];n(e[i],c)&&(o=!0,"object"==typeof c&&"function"!=typeof c.getMonth?r[i]=c.constructor===Array?c.slice(0):f({},c):r[i]=c)}return{diff:r,changed:o}}function o(t,e){t="function"==typeof t?t(e):t;var n={};for(var r in t)!function(r){n[r]=function(){for(var n=[],o=0;o<arguments.length;o++)n[o]=arguments[o];var f=t[r].apply(t,[e.getState()].concat(n));if(null!=f){if(f.then)return f.then(e.setState);e.setState(f)}}}(r);return n}var f=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t};t.connect=function(t,e,n){function o(){var o=r(n(e.getState()),t.get()),f=o.diff;o.changed&&t.set(f)}o(),t.on("destroy",e.subscribe(o))},t.getActions=function(t,e){return o(e,t)},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t["redux-zero"]={})}(this,function(t){"use strict";function e(t,e){for(var n in t)if(t[n]!==e[n])return!1;for(var n in e)if(!(n in t))return!1;return!0}function n(t,n){return t!==n||!(!t||"object"!=typeof t)&&!e(t,n)}function r(t,e){var r={},o=!1;for(var f in t){var c=t[f];n(e[f],c)&&(o=!0,"object"==typeof c&&"function"!=typeof c.getMonth?r[f]=c.constructor===Array?c.slice(0):i({},c):r[f]=c)}return{diff:r,changed:o}}function o(t,e){if(null!=e){if(e.then)return e.then(t.setState);t.setState(e)}}function f(t,e){t="function"==typeof t?t(e):t;var n={};for(var r in t)!function(r){n[r]=function(){for(var n=[],f=0;f<arguments.length;f++)n[f]=arguments[f];var i=t[r];return"function"==typeof e.middleware?e.middleware(e,i,n):o(e,i.apply(void 0,[e.getState()].concat(n)))}}(r);return n}var i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o])}return t};t.connect=function(t,e,n){function o(){var o=r(n(e.getState()),t.get()),f=o.diff;o.changed&&t.set(f)}o(),t.on("destroy",e.subscribe(o))},t.getActions=function(t,e){return f(e,t)},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=index.min.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72672
61
640
194