Skip to content
This repository has been archived by the owner on May 20, 2022. It is now read-only.

Commit

Permalink
updating order of arguments on subscription callback
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonnymichel committed Aug 30, 2019
1 parent 18ee223 commit cc6f49d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion example/subscribe.js
Expand Up @@ -11,7 +11,7 @@ const store = createStore('clickCounter2', 0);
const unsubscribe = store.subscribe((state) => {
alert('You increased the counter!');
if (state >= 3) {
//after three executions, let's unsubscribe to get rid of the alert!
//after three executions, lets unsubscribe to get rid of the alert!
unsubscribe();
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -69,7 +69,7 @@ export function createStore(name, state = {}, reducer=defaultReducer) {
this.state = this.reducer(this.state, action);
this.setters.forEach(setter => setter(this.state));
if (subscriptions[name].length) {
subscriptions[name].forEach(c => c(action, this.state));
subscriptions[name].forEach(c => c(this.state, action));
}
if (typeof callback === 'function') callback(this.state)
},
Expand Down
2 changes: 1 addition & 1 deletion src/tests/subscribe.test.js
Expand Up @@ -20,7 +20,7 @@ describe('store.subscribe', () => {
const subscriber = jest.fn();
store.subscribe(subscriber);
store.dispatch({ type: 'test', payload: 1 });
expect(subscriber).toHaveBeenCalledWith({ type: 'test', payload: 1 }, 1);
expect(subscriber).toHaveBeenCalledWith(1, { type: 'test', payload: 1 });
});

test('cant resubscribe with the same function', () => {
Expand Down

0 comments on commit cc6f49d

Please sign in to comment.