Phrontend uses facebook's dispatcher and follows the concept of a single dispatcher. All actions are dispatched via this dispatcher.
The Dispatcher
exposed from Phrontend is a singleton.
import {Dispatcher} from 'phrontend';
- dispatches an action of type
actionType
with the payloaddata
For all other methods, refer Facebook's dispatcher docs.
import {Store} from 'phrontend';
Store is an abstract class. Your application Store extends this base Store
and defines a method handler
with the following signature
handler(payload : <Object>{ actionType : <String>, data : <Any> }) : void
This handler is registered to the AppDispatcher, and will be called whenever the dispatcher receives an action.
class MyStore extends Store {
handler(payload) {}
}
get()
returns entire state objectget('foo')
returnsstate['foo']
get(5)
returnsstate[5]
- used for Lists
set('foo', 'bar')
doesstate['foo'] = 'bar'
set({ foo: 'bar' })
does the same thing. Use this for setting multiple items together
- parses only String using JSON.parse
- Override in your Store definition to parse API responses in a custom manner
- Listen to change event using successHandler
- Listen to error event using errorHandler
- Unlisten successHandler from the change event
- Unlisten errorHandler from the error event
- emit a change event to all subscribers of the store instance
- emit an error event to all subscribers of the store instance
- Reference to the AppDispatcher's instance
- The store's dispatchToken. Use this to inform dispatcher.waitFor in other Stores
ApiCaller is a singleton that uses whatwg-fetch