• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SAP / ui5-webcomponents-react / 9854624084

09 Jul 2024 09:35AM CUT coverage: 80.554% (-0.2%) from 80.782%
9854624084

Pull #6042

github

web-flow
Merge 780612efc into d4c3bcd8d
Pull Request #6042: refactor(Modals): replace context with use-sync-external-store

2599 of 3809 branches covered (68.23%)

41 of 65 new or added lines in 3 files covered. (63.08%)

4652 of 5775 relevant lines covered (80.55%)

67548.66 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/packages/main/src/internal/ModalStore.ts
1
import type { ComponentType, RefCallback, RefObject } from 'react';
2

3
const STORE_SYMBOL_LISTENERS = Symbol.for('@ui5/webcomponents-react/Modals/Listeners');
387✔
4
const STORE_SYMBOL = Symbol.for('@ui5/webcomponents-react/Modals');
387✔
5

6
type IModal = {
7
  Component: ComponentType;
8
  props: Record<string, unknown>;
9
  ref: RefObject<unknown> | RefCallback<unknown>;
10
  container?: Element | DocumentFragment;
11
  id: string;
12
};
13

14
const initialStore: IModal[] = [];
387✔
15

16
function getListeners(): Array<() => void> {
17
  globalThis[STORE_SYMBOL_LISTENERS] ??= [];
34✔
18
  return globalThis[STORE_SYMBOL_LISTENERS];
34✔
19
}
20

21
function emitChange() {
22
  for (const listener of getListeners()) {
22✔
23
    listener();
22✔
24
  }
25
}
26

27
function getSnapshot(): IModal[] {
28
  globalThis[STORE_SYMBOL] ??= initialStore;
146✔
29
  return globalThis[STORE_SYMBOL];
146✔
30
}
31

32
function subscribe(listener: () => void) {
33
  const listeners = getListeners();
12✔
34
  globalThis[STORE_SYMBOL_LISTENERS] = [...listeners, listener];
12✔
35
  return () => {
12✔
36
    globalThis[STORE_SYMBOL_LISTENERS] = listeners.filter((l) => l !== listener);
8✔
37
  };
38
}
39

40
export const ModalStore = {
387✔
41
  subscribe,
42
  getSnapshot,
43
  getServerSnapshot: () => {
NEW
44
    return initialStore;
×
45
  },
46
  addModal(config: IModal) {
47
    globalThis[STORE_SYMBOL] = [...getSnapshot(), config];
12✔
48
    emitChange();
12✔
49
  },
50
  removeModal(id: string) {
51
    globalThis[STORE_SYMBOL] = getSnapshot().filter((modal) => modal.id !== id);
10✔
52
    emitChange();
10✔
53
  }
54
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc