(store: Store<IReduxState>, datasheetService: { instance: IResourceService | null })
| 23 | import { IResourceService } from 'resource'; |
| 24 | |
| 25 | export 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 | }; |
no test coverage detected