Skip to content
This repository has been archived by the owner on Jun 18, 2023. It is now read-only.

Commit

Permalink
Add class method to reset all stores
Browse files Browse the repository at this point in the history
  • Loading branch information
hugollm committed May 7, 2019
1 parent 54040a0 commit 5d17783
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/true-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class TrueStore {
this.stateMap = this.initialMap;
this.observers = [];
this.transactionDepth = 0;
TrueStore.stores.push(this);
}

get(key = null) {
Expand Down Expand Up @@ -84,6 +85,13 @@ class TrueStore {
}
}

TrueStore.stores = [];

TrueStore.resetAll = function() {
for (let i in TrueStore.stores)
TrueStore.stores[i].reset();
}


class TrueStoreObserver {

Expand Down
14 changes: 14 additions & 0 deletions tests/reset-all.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const TrueStore = require('../src/true-store');

describe('resetAll', () => {

it('returns all stores to their initial state', () => {
let store1 = new TrueStore({foo: 1});
let store2 = new TrueStore({bar: 2});
store1.set('foo',3);
store2.set('bar', 4);
TrueStore.resetAll();
expect(store1.get()).toEqual({foo: 1});
expect(store2.get()).toEqual({bar: 2});
});
});

0 comments on commit 5d17783

Please sign in to comment.