UNPKG

core-native

Version:

A lightweight framework based on React Native + Redux + Redux Saga, in strict TypeScript.

61 lines 1.91 kB
import { app } from "../app"; import { setStateAction } from "../reducer"; export class Module { constructor(name, initialState) { this.name = name; this.initialState = initialState; } *onEnter(routeParameters, path) { /** * Called when the attached component is mounted * The routeParameters and path are specified if the component is connected to React Navigator. */ } *onDestroy() { /** * Called when the attached component is going to unmount */ } *onTick() { /** * Called periodically during the lifecycle of attached component * Usually used together with @Interval decorator, to specify the period (in second) * Attention: The next tick will not be triggered, until the current tick has finished */ } *onAppActive() { /** * Called when the app becomes active (foreground) from background task * Usually used for fetching updated configuration */ } *onAppInactive() { /** * Called when the app becomes inactive (background) from foreground task * Usually used for storing some data into storage */ } *onFocus() { /** * Called when the attached component is connected to React Navigator, and gets focused */ } *onBlur() { /** * Called when the attached component is connected to React Navigator, and gets blurred */ } get state() { return this.rootState.app[this.name]; } get rootState() { return app.store.getState(); } get logger() { return app.logger; } setState(newState) { app.store.dispatch(setStateAction(this.name, newState, `@@${this.name}/setState[${Object.keys(newState).join(",")}]`)); } } //# sourceMappingURL=Module.js.map