The nanoflux Fusion API extends the normal nanoflux API by very few methods only, i.e. you may use nanoflux as usual, or even mix both styles (which I do not recommend, as it mixes concepts)
nanoflux Fusion works with a dedicated single store only. This method returns this store, i.e. a normal nanoflux store. It is already connected to the default dispatcher, so there`s no need to care about the internals.
This store has only three public functions, which are
getState()
, which returns the immutable application state.use()
, which uses a middleware function of type function(newState,currentState, actionName)
. The function object must return an object, considered as new state.subscribe()
, which connects components to listen to changes on this store (the same as in nanoflux)
createFusionator( descriptor, initialState, namespace? )
Creates a Fusionator with optional namespace.
The descriptor is a JSON object containing the Fusionators available functions. The method must return a JSON object or a A+ compliant Promise in case of asynchronous actions. The passed object will become part of the application state then. Each function of a Fusionator has the following signature
where previousState is the immutable application state, and argumentList is an array of arguments passed on the related Actors call.
Additionally, an initial state must be provided, i.e. a JSON object that describes your state at startup/before first action.
The optional namespace argument should be used when breaking Fusionators apart (important for larger applications). With namespace you avoid naming collisions. If a namespace is not given the default namespace is used.
Note: The state object can be of any complexity, as immutability is done recursively. Although, this may have impact on runtime performance, it was proven that performance is sufficient even for several thousand states.
getFusionActor( actorId, namespace? )
Returns a function object, i.e. a specific action for a specific Fusionator. Actors are created automatically when a calling createFusionator(). The actorId is the functions name defined in the Fusionator. Using namespaces helps to avoid naming collisions, when using multiple Fusionators. If namespace is not given the default namespace is used.