diff --git a/lib/flux.js b/lib/flux.js index 7792f94..d9e2e00 100644 --- a/lib/flux.js +++ b/lib/flux.js @@ -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"); diff --git a/site/contents/documentation/flux.md b/site/contents/documentation/flux.md index 654b870..5d791cd 100644 --- a/site/contents/documentation/flux.md +++ b/site/contents/documentation/flux.md @@ -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. diff --git a/test/unit/test_flux.js b/test/unit/test_flux.js index 084439e..58cf0a1 100644 --- a/test/unit/test_flux.js +++ b/test/unit/test_flux.js @@ -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();