From 6c36c86207fb6836d387107e99a0e59e88e7d7e8 Mon Sep 17 00:00:00 2001 From: peternandersson Date: Thu, 19 Sep 2024 15:11:27 -0700 Subject: [PATCH] Change removal to deprecation --- src/client/initialize.ts | 15 ++++++++++++++- src/react/hooks.ts | 2 ++ src/types.ts | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/client/initialize.ts b/src/client/initialize.ts index 1597e94..c44c8fd 100644 --- a/src/client/initialize.ts +++ b/src/client/initialize.ts @@ -12,6 +12,7 @@ export function initialize(): PluginInstance { config: {} as T, }; + let subscribedInteractions: Record = {}; let subscribedWorkbookVars: Record = {}; const registeredEffects: Record void> = {}; @@ -170,6 +171,18 @@ export function initialize(): PluginInstance { off('wb:plugin:variable:update', setValues); }; }, + subscribeToWorkbookInteraction( + id: string, + callback: (input: WorkbookSelection[]) => void, + ): Unsubscriber { + const setValues = (values: Record) => { + callback(values[id]); + }; + on('wb:plugin:selection:update', setValues); + return () => { + off('wb:plugin:selection:update', setValues); + }; + }, }, elements: { getElementColumns(id) { @@ -197,7 +210,7 @@ export function initialize(): PluginInstance { }, fetchMoreElementData(id) { void execPromise('wb:plugin:element:fetch-more', id); - } + }, }, destroy() { Object.keys(listeners).forEach(event => delete listeners[event]); diff --git a/src/react/hooks.ts b/src/react/hooks.ts index 5acf7db..c8f3e65 100644 --- a/src/react/hooks.ts +++ b/src/react/hooks.ts @@ -180,7 +180,9 @@ export function useVariable( return [workbookVariable, setVariable]; } + /** + * @deprecated Use Action API instead * React hook for accessing a workbook interaction selections state * @param {string} id ID of variable within Plugin Config to use * @returns {[(WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof diff --git a/src/types.ts b/src/types.ts index adeb371..176b5bf 100644 --- a/src/types.ts +++ b/src/types.ts @@ -248,12 +248,14 @@ export interface PluginInstance { setVariable(id: string, ...values: unknown[]): void; /** + * @deprecated Use Action API instead * Getter for interaction selection state * @param {string} id ID from interaction type in Plugin Config */ getInteraction(id: string): WorkbookSelection[]; /** + * @deprecated Use Action API instead * Setter for interaction selection state * @param {string} id ID from interaction type in Plugin Config * @param {string} elementId Source element ID from element type in Plugin Config @@ -295,6 +297,18 @@ export interface PluginInstance { id: string, callback: (input: WorkbookVariable) => void, ): Unsubscriber; + + /** + * @deprecated Use Action API instead + * Allows users to subscribe to changes in the passed in interaction ID + * @param {string} id ID of the interaction variable within Plugin Config + * @callback callback Function to be called upon receiving an updated interaction selection state + * @returns {Unsubscriber} A callable unsubscriber + */ + subscribeToWorkbookInteraction( + id: string, + callback: (input: WorkbookSelection[]) => void, + ): Unsubscriber; }; elements: {