call notifications API

Summary:
Adding a static method plugins can implement to trigger notifications:

```
static getActiveNotifications: ?(persistedState: P) => Array<Notification>;
```

When the plugin's persisted state changes, this API is called from the `notification`-dispatcher which updates the notifications store.

Reviewed By: passy

Differential Revision: D10378434

fbshipit-source-id: 778fe3ad4229b03bd5ba14ebfdafa5020c25f34f
This commit is contained in:
Daniel Büchele
2018-10-18 02:45:28 -07:00
committed by Facebook Github Bot
parent ce996ba8af
commit 51f70fd78c
4 changed files with 47 additions and 40 deletions

View File

@@ -10,6 +10,7 @@ import type {App} from './App.js';
import type Logger from './fb-stubs/Logger.js';
import type {Store} from './reducers/index.js';
import {setPluginState} from './reducers/pluginStates.js';
import {clientPlugins} from './plugins/index.js';
import {ReactiveSocket, PartialResponder} from 'rsocket-core';
@@ -169,17 +170,17 @@ export default class Client extends EventEmitter {
if (persistingPlugin) {
const pluginKey = `${this.id}#${params.api}`;
const persistedState = this.store.getState().pluginStates[pluginKey];
this.store.dispatch({
type: 'SET_PLUGIN_STATE',
payload: {
// $FlowFixMe: We checked persistedStateReducer exists
const newPluginState = persistingPlugin.persistedStateReducer(
persistedState,
params.params,
);
this.store.dispatch(
setPluginState({
pluginKey,
// $FlowFixMe: We checked persistedStateReducer exists
state: persistingPlugin.persistedStateReducer(
persistedState,
params.params,
),
},
});
state: newPluginState,
}),
);
} else {
const apiCallbacks = this.broadcastCallbacks.get(params.api);
if (!apiCallbacks) {