MCPcopy Index your code
hub / github.com/apitable/apitable / subscribeWidgetMap

Function subscribeWidgetMap

packages/widget-sdk/src/subscribe/widget_map.ts:25–53  ·  view source on GitHub ↗
(store: Store<IReduxState>, datasheetService: { instance: IResourceService | null })

Source from the content-addressed store, hash-verified

23import { IResourceService } from 'resource';
24
25export const subscribeWidgetMap = (store: Store<IReduxState>, datasheetService: { instance: IResourceService | null }) => {
26 let widgetIds: Set<string> = new Set();
27 return store.subscribe(() => {
28 const state = store.getState();
29 const widgetMap = state.widgetMap;
30 if (!widgetMap || !datasheetService.instance?.checkRoomExist()) {
31 return;
32 }
33 const previousWidgetIds = widgetIds;
34 widgetIds = new Set(Object.keys(widgetMap).filter(item => Boolean(widgetMap[item]!.widget)));
35 if (eqSet(widgetIds, previousWidgetIds)) {
36 return;
37 }
38 const diffOfAdd = difference([...widgetIds], [...previousWidgetIds]);
39 const diffOfDelete = difference([...previousWidgetIds], [...widgetIds]);
40
41 if (diffOfAdd.length) {
42 for (const v of diffOfAdd) {
43 datasheetService.instance.createCollaEngine(v, ResourceType.Widget);
44 }
45 }
46
47 if (diffOfDelete.length) {
48 for (const v of diffOfDelete) {
49 datasheetService.instance.reset(v, ResourceType.Widget);
50 }
51 }
52 });
53};

Callers 2

initGlobalContextFunction · 0.90
widget_map.tsFile · 0.90

Calls 7

eqSetFunction · 0.90
checkRoomExistMethod · 0.65
keysMethod · 0.65
createCollaEngineMethod · 0.65
resetMethod · 0.65
subscribeMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected