Store
ZumoKit SDK stores current application state in a centralized data store.
ZumoKit store implements observer pattern. Using this pattern one can subscribe to state changes and be notified of such changes automatically.
Android
After initializing ZumoKit application store can be accessed by calling:
Store store = this.zumoKit.store();
Methods
Method | Type | Description |
---|---|---|
getState() | State | Returns current application state. |
subscribe(StoreObserver observer) | void | Attaches observer to the list of store observers. |
unsubscribe(StoreObserver observer) | void | Removes observer from the list of store observers. |
getState
State getState()
Returns current application state. See state for details.
subscribe
void subscribe(StoreObserver observer)
Attaches observer to the list of store observers. Observer must implement StoreObserver interface:
public class MyStoreObserver implements StoreObserver {
@Override
public void update(State state) {
// Do something with state
}
}
Update method is called each time application state changes.
unsubscribe
void unsubscribe(StoreObserver observer)
Removes observer from the list of store observers.
iOS
After initializing ZumoKit application store can be accessed by calling:
CPSore *store = [_zumoKit store];
Methods
Method | Type | Description |
---|---|---|
getState | nonnull CPState * | Returns current application state. |
subscribe:(nullable id<CPStoreObserver>)observer | void | Attaches observer to the list of store observers. |
unsubscribe:(nullable id<CPStoreObserver>)observer | void | Removes observer from the list of store observers. |
getState
(nonnull CPState *)getState
Returns current application state. See state for details.
subscribe
(void)subscribe:(nullable id<CPStoreObserver>)observer
Attaches observer to the list of store observers. Observer must implement CPStoreObserver interface:
@interface MyStoreObserver : NSObject <CPStoreObserver>
- (void)update:(nonnull CPState *)state;
@end
Update method is called each time application state changes.
unsubscribe
(void)unsubscribe:(nullable id<CPStoreObserver>)observer;
Removes observer from the list of store observers.
React Native
After initializing ZumoKit, a listener can be added through the ZumoKit
singleton.
Methods
Method | Type | Description |
---|---|---|
addListener | EmitterSubscription | Returns the listener subscription. |
addListener
const subscription = ZumoKit.addListener(() => { });
remove
A subscription should be removed when a component is unmounted.
componentWillUnmount() {
subscription.remove();
}