introduce onReady life-cycle

Summary: Flipper Sandy plugins didn't have an event to hook into that is run _after_ any state snapshot is loaded, which was needed by the graphQL plugin, as they do some post processing when a data snapshot is restored.

Reviewed By: passy

Differential Revision: D28189573

fbshipit-source-id: 4ef992f3fafc32787eab3bc235059f2c41396c80
This commit is contained in:
Michel Weststrate
2021-05-04 12:51:32 -07:00
committed by Facebook GitHub Bot
parent 616341f649
commit dd7a9f5195
5 changed files with 57 additions and 19 deletions

View File

@@ -28,6 +28,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
const activateStub = jest.fn();
const deactivateStub = jest.fn();
const destroyStub = jest.fn();
const readyStub = jest.fn();
const state = createState(
{
count: 0,
@@ -43,6 +44,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
client.onActivate(activateStub);
client.onDeactivate(deactivateStub);
client.onDestroy(destroyStub);
client.onReady(readyStub);
client.onMessage('inc', ({delta}) => {
state.update((draft) => {
draft.count += delta;
@@ -81,6 +83,7 @@ export function plugin(client: PluginClient<Events, Methods>) {
connectStub,
destroyStub,
disconnectStub,
readyStub,
getCurrentState,
state,
unhandledMessages,