Not Flux
What is Not Flux
It's a flux library :) Implemented in angular to provide a quick flux pattern without having to worry about using emitChange
everywhere
Features
- Actions and Stores
- Stores emit clones
- NO EMIT CHANGE!!
- Can have private functions/methods
Examples
Creating a store
Creating actions
Linking Actions to Stores
Linking up the view
// We must load up the store as well as the actions. This is// so the store can be initialzed! You only// need to initialize a store in one location// though it will not effect anything doing so in multiple places
Methods
Store
Outside the definition
.bindTo($scope, cb)
This is for binding to the data of a store. To modify the datastream we can use tranformFn
.data(waitedAttrs)
This allows you to pull a clone of the data from the store. You can optionally pass it a single string or an array of strings to clone it once it's been filled but this required you to set it to null for initialization.
IE.
// hello.myData will contain the result$scopehello = MyStoredata'myData'result // Sets $scope.myData and $scope.waiting to the data from the store once its resolvedMyStoredata'myData' 'waiting'
Inside the definition
.init
A method to overload for initialization of the store. Used to bind actions.
init: function() {
// Set `setUserId` to run store.changedUserId
SettingsActions.setUserId.listen(this.changeUserId)
// We can even define multiple handlers
SettingsActions.changeInfo.listen([this.modifyInfo, this.changeUserId])
},
.transformFn(data)
This is so you can modify the outgoing stream from the store. IE.
NotFlux
.emit(data)
Use this to emit system wide events IE.
NotFlux $scope
Actions
Actions.{name}.listen(handler)
Setup a listener for an action