Comparing version 4.0.0 to 4.0.1
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):factory(global.fluxury={})})(this,function(exports){"use strict";function Dispatcher(){var lastId=1;var prefix="ID_";var callbacks={};var isPending={};var isDispatching=false;var pendingPayload=null;function invokeCallback(id){isPending[id]=true;callbacks[id](pendingPayload)}this.register=function(callback){var id=prefix+lastId++;callbacks[id]=callback;return id};this.unregister=function(id){if(!callbacks.hasOwnProperty(id)){return new Error("Cannot unregister unknown ID!")}delete callbacks[id];return id};this.waitFor=function(ids){for(var i=0;i<ids.length;i++){var id=ids[id];if(isPending[id]){return new Error("Circular dependency waiting for "+id)}if(!callbacks[id]){return new Error("waitFor: "+id+" is not a registered callback.")}invokeCallback(id)}return undefined};this.dispatch=function(payload){if(isDispatching){return new Error("Cannot dispatch while dispatching.")}for(var id in callbacks){isPending[id]=false}pendingPayload=payload;isDispatching=true;try{for(var id in callbacks){if(isPending[id]){continue}invokeCallback(id)}}finally{pendingPayload=null;isDispatching=false}return payload}}var rootState=Object.freeze({}),stores={},dispatcher=new Dispatcher,waitFor=dispatcher.waitFor.bind(dispatcher),rootListeners=[],rootNextListeners=[];function copyIfSame(current,next){if(current===next){return current.slice()}return next}function updateRootState(name,newState){var changes={};changes[name]=typeof newState==="object"?Object.freeze(newState):newState;rootState=Object.assign({},rootState,changes)}function rootNotify(action){var listeners=rootListeners=rootNextListeners;for(var i=0;i<listeners.length;i++){var listener=listeners[i];listener(rootState,action)}}function subscribe(cb){if(typeof cb!=="function"){throw"Listener must be a function"}var subscribed=true;rootNextListeners=copyIfSame(rootListeners,rootNextListeners);rootNextListeners.push(cb);return function(){if(!subscribed){return}subscribed=false;rootNextListeners=copyIfSame(rootListeners,rootNextListeners);var index=rootNextListeners.indexOf(cb);rootNextListeners.splice(index,1)}}function promiseAction(type,data){return Promise.resolve({type:type,data:data})}function replaceState(newState){rootState=newState}function dispatch(action,data){try{if(typeof action==="object"&&typeof action.then==="function"){return action.then(function(result){dispatch(result);return Promise.resolve(result)})}else if(typeof action==="object"){}else if(typeof action==="string"){action={type:action,data:data}}else{return Promise.reject("Invalid action!")}var currentState=rootState;dispatcher.dispatch(action);if(currentState!==rootState){rootNotify(action)}return Promise.resolve(action)}catch(e){return Promise.reject(e)}}function makeReducer(spec){return function(state,action){if(action&&typeof action.type==="string"&&spec.hasOwnProperty(action.type)){return spec[action.type](state,action.data,waitFor)}return state}}function bindSelectors(name,selectors){return Object.keys(selectors).reduce(function(a,b,i){var newFunc={};newFunc[b]=function(){var params=[],len=arguments.length;while(len--)params[len]=arguments[len];return selectors[b].apply(selectors,[rootState[name]].concat(params))};return Object.assign(a,newFunc)},{})}function getState(){return rootState}function getStores(){return stores}function createStore(name,reducerOrSpec,selectors){if(selectors===void 0)selectors={};if(typeof name!=="string"){throw"Expect name to be string."}if(typeof reducerOrSpec!=="function"&&typeof reducerOrSpec!=="object"){throw"Expect reducer to be function or object spec."}if(typeof selectors!=="object"){throw"Expect selectors to be object."}var isSpec=typeof reducerOrSpec==="object",reducer=isSpec?makeReducer(reducerOrSpec):reducerOrSpec,actions={},currentListeners=[],nextListeners=[];updateRootState(name,isSpec?reducerOrSpec.getInitialState?reducerOrSpec.getInitialState():undefined:reducer(undefined,{},function(){}));rootNotify(undefined);var dispatchToken=dispatcher.register(function(action){var newState=reducer(rootState[name],action,waitFor);if(rootState[name]!==newState){updateRootState(name,newState);var listeners=currentListeners=nextListeners;for(var i=0;i<listeners.length;i++){var listener=listeners[i];listener(newState,action)}}});function subscribe(cb){if(typeof cb!=="function"){throw"Listener must be a function"}var subscribed=true;nextListeners=copyIfSame(currentListeners,nextListeners);nextListeners.push(cb);return function(){if(!subscribed){return}subscribed=false;nextListeners=copyIfSame(currentListeners,nextListeners);var index=nextListeners.indexOf(cb);nextListeners.splice(index,1)}}if(isSpec){actions=Object.keys(reducerOrSpec).reduce(function(a,b){if(b==="getInitialState"){return a}a[b]=function(data){return dispatch({type:b,data:data})};return a},{})}var store=Object.assign({},actions,bindSelectors(name,selectors),{name:name,dispatch:function(){var action=[],len=arguments.length;while(len--)action[len]=arguments[len];return dispatch.apply(void 0,action)},dispatchToken:dispatchToken,subscribe:subscribe,replaceReducer:function(newReducer){return reducer=newReducer},setState:function(state){updateRootState(name,state)},getReducer:function(){return reducer},getState:function(){return rootState[name]}});if(name[0]!=="_"){stores[name]=store}return store}exports.subscribe=subscribe;exports.promiseAction=promiseAction;exports.replaceState=replaceState;exports.dispatch=dispatch;exports.getState=getState;exports.getStores=getStores;exports.createStore=createStore;Object.defineProperty(exports,"__esModule",{value:true})}); |
{ | ||
"name": "fluxury", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "state management in js", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
# fluxury | ||
[](https://circleci.com/gh/jcfisher007/fluxury/tree/master) | ||
[](https://circleci.com/gh/fluxury/fluxury/tree/master) | ||
@@ -5,0 +5,0 @@ ## Overview |
@@ -0,0 +0,0 @@ var test = require("tape-async"); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35181
10
0