MCPcopy
hub / github.com/tinyplex/tinybase / useThing

Function useThing

src/ui-solid/context.ts:87–106  ·  view source on GitHub ↗
(
  id: MaybeAccessor<Id | undefined>,
  offset: Offsets,
)

Source from the content-addressed store, hash-verified

85 createContext<ContextValueAccessor>(EMPTY_CONTEXT_VALUE));
86
87export const useThing = <UsedThing extends Thing>(
88 id: MaybeAccessor<Id | undefined>,
89 offset: Offsets,
90): Accessor<UsedThing | undefined> => {
91 const contextValue = useContext(Context)?.value ?? EMPTY_CONTEXT;
92 return () => {
93 const resolvedContextValue = contextValue();
94 const resolvedId = getValue(id);
95 return (
96 isUndefined(resolvedId)
97 ? resolvedContextValue[offset * 2]
98 : isString(resolvedId)
99 ? objGet(
100 resolvedContextValue[offset * 2 + 1] as IdObj<UsedThing>,
101 resolvedId,
102 )
103 : resolvedId
104 ) as UsedThing;
105 };
106};
107
108export const useThings = <UsedThing extends Thing>(
109 offset: Offsets,

Callers 9

useStoreFunction · 0.90
useMetricsFunction · 0.90
useIndexesFunction · 0.90
useRelationshipsFunction · 0.90
useQueriesFunction · 0.90
useCheckpointsFunction · 0.90
usePersisterFunction · 0.90
useSynchronizerFunction · 0.90
useThingOrThingByIdFunction · 0.70

Calls 4

getValueFunction · 0.90
isUndefinedFunction · 0.90
isStringFunction · 0.90
objGetFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…