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

SAP / ui5-webcomponents-react / 10510216342

22 Aug 2024 02:35PM CUT coverage: 87.91% (+0.4%) from 87.477%
10510216342

Pull #6247

github

web-flow
Merge e7f90c215 into 8184b4e98
Pull Request #6247: chore: use React18

2833 of 3762 branches covered (75.31%)

5068 of 5765 relevant lines covered (87.91%)

92234.69 hits per line

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

95.24
/packages/main/src/internal/ModalStore.ts
1
import { getCurrentRuntimeIndex } from '@ui5/webcomponents-base/dist/Runtimes.js';
2
import type { ComponentType, RefCallback, RefObject } from 'react';
3

4
globalThis['@ui5/webcomponents-react'] ??= {};
406✔
5
const STORE_LOCATION = globalThis['@ui5/webcomponents-react'];
406✔
6

7
function getStyleStoreListenersSymbol() {
8
  return Symbol.for(`@ui5/webcomponents-react/Modals-${getCurrentRuntimeIndex()}/Listeners`);
88✔
9
}
10

11
function getStyleStoreSymbol() {
12
  return Symbol.for(`@ui5/webcomponents-react/Modals-${getCurrentRuntimeIndex()}`);
314✔
13
}
14

15
type IModal = {
16
  Component: ComponentType;
17
  props: Record<string, unknown>;
18
  ref: RefObject<unknown> | RefCallback<unknown>;
19
  container?: Element | DocumentFragment;
20
  id: string;
21
};
22

23
const initialStore: IModal[] = [];
406✔
24

25
function getListeners(): Array<() => void> {
26
  STORE_LOCATION[getStyleStoreListenersSymbol()] ??= [];
34✔
27
  return STORE_LOCATION[getStyleStoreListenersSymbol()];
34✔
28
}
29

30
function emitChange() {
31
  for (const listener of getListeners()) {
22✔
32
    listener();
22✔
33
  }
34
}
35

36
function getSnapshot(): IModal[] {
37
  STORE_LOCATION[getStyleStoreSymbol()] ??= initialStore;
146✔
38
  return STORE_LOCATION[getStyleStoreSymbol()];
146✔
39
}
40

41
function subscribe(listener: () => void) {
42
  const listeners = getListeners();
12✔
43
  STORE_LOCATION[getStyleStoreListenersSymbol()] = [...listeners, listener];
12✔
44
  return () => {
12✔
45
    STORE_LOCATION[getStyleStoreListenersSymbol()] = listeners.filter((l) => l !== listener);
8✔
46
  };
47
}
48

49
export const ModalStore = {
406✔
50
  subscribe,
51
  getSnapshot,
52
  getServerSnapshot: () => {
53
    return initialStore;
×
54
  },
55
  addModal(config: IModal) {
56
    STORE_LOCATION[getStyleStoreSymbol()] = [...getSnapshot(), config];
12✔
57
    emitChange();
12✔
58
  },
59
  removeModal(id: string) {
60
    STORE_LOCATION[getStyleStoreSymbol()] = getSnapshot().filter((modal) => modal.id !== id);
10✔
61
    emitChange();
10✔
62
  }
63
};
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