Skip to content

Commit

Permalink
Change removal to deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
peternandersson committed Sep 19, 2024
1 parent 2b8c6d6 commit 6c36c86
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/client/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export function initialize<T = {}>(): PluginInstance<T> {
config: {} as T,
};

let subscribedInteractions: Record<string, WorkbookSelection[]> = {};
let subscribedWorkbookVars: Record<string, WorkbookVariable> = {};
const registeredEffects: Record<string, () => void> = {};

Expand Down Expand Up @@ -170,6 +171,18 @@ export function initialize<T = {}>(): PluginInstance<T> {
off('wb:plugin:variable:update', setValues);
};
},
subscribeToWorkbookInteraction(
id: string,
callback: (input: WorkbookSelection[]) => void,
): Unsubscriber {
const setValues = (values: Record<string, WorkbookSelection[]>) => {
callback(values[id]);
};
on('wb:plugin:selection:update', setValues);
return () => {
off('wb:plugin:selection:update', setValues);
};
},
},
elements: {
getElementColumns(id) {
Expand Down Expand Up @@ -197,7 +210,7 @@ export function initialize<T = {}>(): PluginInstance<T> {
},
fetchMoreElementData(id) {
void execPromise('wb:plugin:element:fetch-more', id);
}
},
},
destroy() {
Object.keys(listeners).forEach(event => delete listeners[event]);
Expand Down
2 changes: 2 additions & 0 deletions src/react/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,14 @@ export interface PluginInstance<T = any> {
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
Expand Down Expand Up @@ -295,6 +297,18 @@ export interface PluginInstance<T = any> {
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: {
Expand Down

0 comments on commit 6c36c86

Please sign in to comment.