defaultPersistedState

Summary: adding a `static defaultPersistedState` which plugins can use to populate their persistedState for the first render.

Reviewed By: passy

Differential Revision: D10446987

fbshipit-source-id: eb37553db7bbec31edf5b4972176e71f303639fe
This commit is contained in:
Daniel Büchele
2018-10-19 05:12:27 -07:00
committed by Facebook Github Bot
parent d48f93edea
commit 4090c2d096
3 changed files with 11 additions and 2 deletions

View File

@@ -169,7 +169,10 @@ export default class Client extends EventEmitter {
if (persistingPlugin) { if (persistingPlugin) {
const pluginKey = `${this.id}#${params.api}`; const pluginKey = `${this.id}#${params.api}`;
const persistedState = this.store.getState().pluginStates[pluginKey]; const persistedState = {
...persistingPlugin.defaultPersistedState,
...this.store.getState().pluginStates[pluginKey],
};
// $FlowFixMe: We checked persistedStateReducer exists // $FlowFixMe: We checked persistedStateReducer exists
const newPluginState = persistingPlugin.persistedStateReducer( const newPluginState = persistingPlugin.persistedStateReducer(
persistedState, persistedState,

View File

@@ -135,7 +135,12 @@ class PluginContainer extends Component<Props, State> {
const props: PluginProps<Object> = { const props: PluginProps<Object> = {
key: pluginKey, key: pluginKey,
logger: this.props.logger, logger: this.props.logger,
persistedState: pluginStates[pluginKey] || {}, persistedState: activePlugin.defaultPersistedState
? {
...activePlugin.defaultPersistedState,
...pluginStates[pluginKey],
}
: pluginStates[pluginKey],
setPersistedState: state => setPluginState({pluginKey, state}), setPersistedState: state => setPluginState({pluginKey, state}),
target, target,
deepLinkPayload: this.props.deepLinkPayload, deepLinkPayload: this.props.deepLinkPayload,

View File

@@ -52,6 +52,7 @@ export class FlipperBasePlugin<
static icon: string = 'apps'; static icon: string = 'apps';
static keyboardActions: ?KeyboardActions; static keyboardActions: ?KeyboardActions;
static screenshot: ?string; static screenshot: ?string;
static defaultPersistedState: PersistedState;
// forbid instance properties that should be static // forbid instance properties that should be static
title: empty; title: empty;