chopped-redux
Advanced tools
Comparing version 4.0.0 to 5.0.0
13
index.js
@@ -13,6 +13,2 @@ | ||
function replaceState (nextState) { | ||
state = nextState | ||
} | ||
function dispatch (action) { | ||
@@ -37,12 +33,5 @@ action = action || {} | ||
getState: getState, | ||
replaceState: replaceState, | ||
dispatch: dispatch, | ||
subscribe: subscribe, | ||
get updater () { | ||
return update | ||
}, | ||
set updater (fn) { | ||
update = fn | ||
} | ||
subscribe: subscribe | ||
} | ||
} |
{ | ||
"name": "chopped-redux", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "An implementation of @gaearon Redux", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -5,3 +5,3 @@ # Chopped Redux | ||
This library is an implementation (a subset?) of [@gaearon](https://github.com/gaearon) [Redux](https://github.com/gaearon/redux), which claims to be a "Predictable state container for JavaScript apps". | ||
This library is an implementation of [@gaearon](https://github.com/gaearon) [Redux](https://github.com/gaearon/redux), which claims to be a "Predictable state container for JavaScript apps". | ||
@@ -18,9 +18,7 @@ Redux is based on [Facebook's Flux](https://facebook.github.io/flux/) but it's a lot more simple a straightforward. Chopped Redux follows the same principles and ideas but cutting off features, namely all utility methods and ES2015/7 magic. Chopped is practically the same as Redux's 1.0 core, just [read the source](https://github.com/acstll/chopped-redux/blob/master/index.js). | ||
- There’s no init dispatch on `createStore()`, you need to do that yourself when you know it’s time to initialize your state. | ||
- You can pass anything to `dispatch()`, not only a plain object, it's your responsibility to handle that in the `update function. | ||
- There’s no init `@@redux/INIT` dispatch on `createStore()`, you need to do that yourself when you know it’s time to initialize your state. | ||
- You can pass anything to `dispatch()`, not only a plain object, it's your responsibility to handle that in the `update` function. | ||
- You can call `dispatch()` with no arguments (an empty object will get dispatched), useful for initializing. | ||
- The dispatched `action` gets passed to listeners. | ||
- The `reducer` function is called `update` (this is just aesthetics). | ||
- There's an extra method `replaceState` (use carefully, the whole point of Redux is to make state changes sane and predictable). | ||
- `getReducer` and `replaceReducer` methods are missing. | ||
@@ -86,3 +84,2 @@ ## Install | ||
- `subscribe` | ||
- `replaceState` | ||
@@ -128,9 +125,6 @@ The factory has a single mandatory param which is a `update` function. | ||
#### `replaceState(state)` | ||
## Old replaceState | ||
- Returns `undefined` | ||
- *state* `Mixed` Whatever your state is | ||
In previous versions (<=4.0.0) there was a `replaceState` method, this was a shortcut for an action that can be easily achieved in a pure Redux manner: By dispatching a `REPLACE_STATE`-typed action and swapping the new state in the `update` function. | ||
This will replace the current state reference in your `store` instance. This could be used for debugging, time-travel, etc. Beware you need to call `dispatch` after replacing the state if you want your views to update or whatever. | ||
## Async and action creators | ||
@@ -137,0 +131,0 @@ |
@@ -10,2 +10,3 @@ | ||
var DECREMENT_COUNTER = 'DECREMENT_COUNTER' | ||
var REPLACE_STATE = 'REPLACE_STATE' | ||
@@ -35,2 +36,5 @@ // Action helpers | ||
break | ||
case REPLACE_STATE: | ||
state = action.payload | ||
break | ||
} | ||
@@ -112,3 +116,3 @@ | ||
var off2 = store.subscribe(function () { | ||
t.equal(store.getState().get('counter'), 6, 'can be remove from within (x1)') | ||
t.equal(store.getState().get('counter'), 6, 'can be removed from within (x1)') | ||
off2() | ||
@@ -157,31 +161,14 @@ }) | ||
test('replaceState', function (t) { | ||
// just proof of concept, not testing anything | ||
test('old replaceState is possible using pure Redux', function (t) { | ||
t.plan(2) | ||
var initialState = { counter: -1 } | ||
var store = createStore(update, initialState) | ||
var store = createStore(update, { counter: 99 }) | ||
var dispatch = store.dispatch | ||
increment(store.dispatch) | ||
t.equal(store.getState().counter, 0, '(test dispatch)') | ||
dispatch({ type: INCREMENT_COUNTER }) | ||
t.equal(store.getState().counter, 100, 'yes') | ||
store.replaceState({ counter: 24 }) | ||
decrement(store.dispatch) | ||
t.equal(store.getState().counter, 23, 'works') | ||
dispatch({ type: REPLACE_STATE, payload: { counter: 25 } }) | ||
t.equal(store.getState().counter, 25, 'it is') | ||
}) | ||
test('`updater` property', function (t) { | ||
t.plan(3) | ||
var store = createStore(update) | ||
store.dispatch() | ||
t.equal(store.getState().counter, 10) | ||
t.equal(typeof store.updater, 'function', 'is getter') | ||
store.updater = function (state, action) { | ||
return { counter: 99 } | ||
} | ||
store.dispatch() | ||
t.equal(store.getState().counter, 99, 'is setter') | ||
}) |
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
11952
152
187