Skip to content

Commit

Permalink
Add Flux#getAllStores() method
Browse files Browse the repository at this point in the history
  • Loading branch information
BinaryMuse committed Jul 27, 2015
1 parent 7f9febb commit 1e43e1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/flux.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ Flux.prototype.store = function(name) {
return this.stores[name];
};

Flux.prototype.getAllStores = function() {
return this.stores;
};

Flux.prototype.addStore = function(name, store) {
if (name in this.stores) {
throw new Error("A store named '" + name + "' already exists");
Expand Down
6 changes: 6 additions & 0 deletions site/contents/documentation/flux.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ var flux = new Fluxxor.Flux(stores, actions);
var myStore = flux.store("MyStore");
```

## `Fluxxor.Flux#getAllStores()`

Retrieves all stores. The return value is an object where the keys are the names of the stores and the values are the stores themselves.

**Note:** This is a reference to the underlying stores implementation, and should not be modified.

## `Fluxxor.Flux#actions`

Retrieves the map of actions.
Expand Down
8 changes: 8 additions & 0 deletions test/unit/test_flux.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ describe("Flux", function() {
expect(flux.store("Store2")).to.equal(store2);
});

it("allows retrieval of all stores", function() {
var store1 = {};
var store2 = {};
var store3 = {};
var flux = new Fluxxor.Flux({store1: store1, store2: store2, store3: store3});
expect(flux.getAllStores()).to.eql({store1: store1, store2: store2, store3: store3});
});

it("does not allow duplicate stores", function() {
var store1 = {};
var flux = new Fluxxor.Flux();
Expand Down

0 comments on commit 1e43e1d

Please sign in to comment.