@@ -55,14 +55,15 @@ import {
5555 useRelationshipsOrRelationshipsById ,
5656} from './context' ;
5757import { Id , Ids } from '../types/common.d' ;
58- import React , { ReactElement , useContext } from 'react' ;
58+ import React , { ReactElement } from 'react' ;
5959import {
6060 createElement ,
6161 getIndexStoreTableId ,
6262 getProps ,
6363 getRelationshipsStoreTableIds ,
6464} from './common' ;
6565import { isArray , isUndefined } from '../common/other' ;
66+ import { objDel , objGet } from '../common/obj' ;
6667import {
6768 useCell ,
6869 useCellIds ,
@@ -86,9 +87,10 @@ import {
8687} from './hooks' ;
8788import { CheckpointIds } from '../types/checkpoints' ;
8889import { EMPTY_STRING } from '../common/strings' ;
90+ import { Store } from '../types/store' ;
8991import { arrayMap } from '../common/array' ;
9092
91- const { useMemo} = React ;
93+ const { useCallback , useContext , useMemo, useState } = React ;
9294
9395const tableView = (
9496 {
@@ -236,12 +238,31 @@ export const Provider: typeof ProviderDecl = ({
236238 children,
237239} : ProviderProps & { readonly children : React . ReactNode } ) : any => {
238240 const parentValue = useContext ( Context ) ;
241+
242+ const [ extraStoresById , setExtraStoresById ] = useState < { [ id : Id ] : Store } > ( { } ) ;
243+ const addExtraStore = useCallback (
244+ ( id : Id , store : Store ) =>
245+ setExtraStoresById ( ( extraStoresById ) =>
246+ objGet ( extraStoresById , id ) == store
247+ ? extraStoresById
248+ : { ...extraStoresById , [ id ] : store } ,
249+ ) ,
250+ [ ] ,
251+ ) ;
252+ const delExtraStore = useCallback (
253+ ( id : Id ) =>
254+ setExtraStoresById ( ( extraStoresById ) => ( {
255+ ...objDel ( extraStoresById , id ) ,
256+ } ) ) ,
257+ [ ] ,
258+ ) ;
259+
239260 return (
240261 < Context . Provider
241262 value = { useMemo (
242263 ( ) => [
243264 store ?? parentValue [ 0 ] ,
244- { ...parentValue [ 1 ] , ...storesById } ,
265+ { ...parentValue [ 1 ] , ...storesById , ... extraStoresById } ,
245266 metrics ?? parentValue [ 2 ] ,
246267 { ...parentValue [ 3 ] , ...metricsById } ,
247268 indexes ?? parentValue [ 4 ] ,
@@ -252,10 +273,13 @@ export const Provider: typeof ProviderDecl = ({
252273 { ...parentValue [ 9 ] , ...queriesById } ,
253274 checkpoints ?? parentValue [ 10 ] ,
254275 { ...parentValue [ 11 ] , ...checkpointsById } ,
276+ addExtraStore ,
277+ delExtraStore ,
255278 ] ,
256279 [
257280 store ,
258281 storesById ,
282+ extraStoresById ,
259283 metrics ,
260284 metricsById ,
261285 indexes ,
@@ -267,6 +291,8 @@ export const Provider: typeof ProviderDecl = ({
267291 checkpoints ,
268292 checkpointsById ,
269293 parentValue ,
294+ addExtraStore ,
295+ delExtraStore ,
270296 ] ,
271297 ) }
272298 >
0 commit comments