Comparing version 0.3.0 to 0.4.0
@@ -11,32 +11,29 @@ "use strict"; | ||
var store = null; | ||
function initialize(initialState) { | ||
if (!store) { | ||
var state = computeState(initialState); | ||
var listeners = []; | ||
var dispatch = function dispatch(action) { | ||
if (action.jam) { | ||
return action(dispatch); | ||
} | ||
var state = computeState(initialState); | ||
var listeners = []; | ||
var dispatch = function dispatch(action) { | ||
if (action.jam) { | ||
return action(dispatch); | ||
} | ||
state = computeState(state, action); | ||
listeners.forEach(function (l) { | ||
return l(state); | ||
}); | ||
state = computeState(state, action); | ||
listeners.forEach(function (l) { | ||
return l(state); | ||
}); | ||
return state; | ||
}; | ||
return { | ||
subscribe: function subscribe(listener) { | ||
return listeners.push(listener); | ||
}, | ||
unsubscribe: function unsubscribe(listener) { | ||
return listeners.splice(listeners.indexOf(listener), 1); | ||
}, | ||
getState: function getState() { | ||
return state; | ||
}; | ||
store = { | ||
subscribe: function subscribe(listener) { | ||
return listeners.push(listener); | ||
}, | ||
getState: function getState() { | ||
return state; | ||
}, | ||
dispatch: dispatch | ||
}; | ||
} | ||
return store; | ||
} | ||
}, | ||
dispatch: dispatch | ||
}; | ||
} |
{ | ||
"name": "apothecary", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Your local friendly storekeeper", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -13,1 +13,15 @@ import initialize from '../src/store'; | ||
}); | ||
test('ability to unsubscribe', () => { | ||
const store = initialize({ n: 1 }); | ||
const inc = state => ({ ...state, n: state.n + 1 }); | ||
const callback = jest.fn(); | ||
store.subscribe(callback); | ||
store.dispatch(inc); | ||
store.unsubscribe(callback); | ||
store.dispatch(inc); | ||
expect(callback.mock.calls.length).toBe(1); | ||
}); |
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
120667
130
11