(
props: ProviderProps & {readonly children: JSXElement},
)
| 46 | const EMPTY_CONTEXT = () => [] as ContextValue; |
| 47 | |
| 48 | export const Provider = ( |
| 49 | props: ProviderProps & {readonly children: JSXElement}, |
| 50 | ): JSXElement => { |
| 51 | const parentValue = |
| 52 | useContext(Context)?.value ?? (EMPTY_CONTEXT as Accessor<ContextValue>); |
| 53 | const [extraThingsById, setExtraThingsById] = createSignal<ExtraThingsById>( |
| 54 | arrayNew(8, () => ({})) as ExtraThingsById, |
| 55 | ); |
| 56 | |
| 57 | const addExtraThingById = <Offset extends Offsets>( |
| 58 | thingOffset: Offset, |
| 59 | id: Id, |
| 60 | thing: ThingsByOffset[Offset], |
| 61 | ): void => { |
| 62 | setExtraThingsById((extraThingsById) => |
| 63 | objGet( |
| 64 | extraThingsById[thingOffset] as IdObj<ThingsByOffset[Offset]>, |
| 65 | id, |
| 66 | ) == thing |
| 67 | ? extraThingsById |
| 68 | : (arrayWith(extraThingsById, thingOffset, { |
| 69 | ...(extraThingsById[thingOffset] as IdObj<ThingsByOffset[Offset]>), |
| 70 | [id]: thing, |
| 71 | } as ThingsById<ThingsByOffset>[Offset]) as ExtraThingsById), |
| 72 | ); |
| 73 | }; |
| 74 | |
| 75 | const delExtraThingById = (thingOffset: Offsets, id: Id): void => { |
| 76 | setExtraThingsById((extraThingsById) => |
| 77 | !objHas(extraThingsById[thingOffset], id) |
| 78 | ? extraThingsById |
| 79 | : (arrayWith( |
| 80 | extraThingsById, |
| 81 | thingOffset, |
| 82 | objDel( |
| 83 | extraThingsById[thingOffset] as IdObj< |
| 84 | ThingsByOffset[typeof thingOffset] |
| 85 | >, |
| 86 | id, |
| 87 | ), |
| 88 | ) as ExtraThingsById), |
| 89 | ); |
| 90 | }; |
| 91 | |
| 92 | const contextValue = createMemo<ContextValue>(() => [ |
| 93 | ...mergeParentThings( |
| 94 | OFFSET_STORE, |
| 95 | parentValue(), |
| 96 | props.store, |
| 97 | props.storesById, |
| 98 | extraThingsById(), |
| 99 | ), |
| 100 | ...mergeParentThings( |
| 101 | OFFSET_METRICS, |
| 102 | parentValue(), |
| 103 | props.metrics, |
| 104 | props.metricsById, |
| 105 | extraThingsById(), |
nothing calls this directly
no test coverage detected
searching dependent graphs…