MCPcopy Index your code
hub / github.com/tinyplex/tinybase / getDefinableFunctions

Function getDefinableFunctions

docs/pseudo.esm.sh/tinybase@9.0.0/index.js:238–359  ·  view source on GitHub ↗
(store, getDefaultThing, validateRowValue, addListener, callListeners)

Source from the content-addressed store, hash-verified

236);
237var setAdd = (set, value) => set?.add(value);
238var getDefinableFunctions = (store, getDefaultThing, validateRowValue, addListener, callListeners) => {
239 const hasRow = store.hasRow;
240 const tableIds = mapNew();
241 const things = mapNew();
242 const thingIdListeners = mapNew();
243 const allRowValues = mapNew();
244 const allSortKeys = mapNew();
245 const storeListenerIds = mapNew();
246 const getStore = () => store;
247 const getThingIds = () => mapKeys(tableIds);
248 const forEachThing = (cb) => mapForEach(things, cb);
249 const hasThing = (id2) => collHas(things, id2);
250 const getTableId = (id2) => mapGet(tableIds, id2);
251 const getThing = (id2) => mapGet(things, id2);
252 const setThing = (id2, thing) => mapSet(things, id2, thing);
253 const addStoreListeners = (id2, ...listenerIds) => {
254 const set = mapEnsure(storeListenerIds, id2, setNew);
255 arrayForEach(listenerIds, (listenerId) => setAdd(set, listenerId));
256 };
257 const delStoreListeners = (id2) => ifNotUndefined(mapGet(storeListenerIds, id2), (allListenerIds) => {
258 arrayForEach(collValues(allListenerIds), (listenerId) => {
259 store.delListener(listenerId);
260 collDel(allListenerIds, listenerId);
261 });
262 mapSet(storeListenerIds, id2);
263 });
264 const setDefinition = (id2, tableId) => {
265 mapSet(tableIds, id2, tableId);
266 if (!collHas(things, id2)) {
267 mapSet(things, id2, getDefaultThing());
268 mapSet(allRowValues, id2, mapNew());
269 mapSet(allSortKeys, id2, mapNew());
270 callListeners(thingIdListeners);
271 }
272 };
273 const setDefinitionAndListen = (id2, tableId, onChanged, getRowValue, getSortKey) => {
274 setDefinition(id2, tableId);
275 const changedRowValues = mapNew();
276 const changedSortKeys = mapNew();
277 const rowValues = mapGet(allRowValues, id2);
278 const sortKeys = mapGet(allSortKeys, id2);
279 const processRow = (rowId) => {
280 const getCell = (cellId) => store.getCell(tableId, rowId, cellId);
281 const oldRowValue = mapGet(rowValues, rowId);
282 const newRowValue = hasRow(tableId, rowId) ? validateRowValue(getRowValue(getCell, rowId)) : void 0;
283 if (!(oldRowValue === newRowValue || isArray(oldRowValue) && isArray(newRowValue) && arrayIsEqual(oldRowValue, newRowValue))) {
284 mapSet(changedRowValues, rowId, [oldRowValue, newRowValue]);
285 }
286 if (!isUndefined(getSortKey)) {
287 const oldSortKey = mapGet(sortKeys, rowId);
288 const newSortKey = hasRow(tableId, rowId) ? getSortKey(getCell, rowId) : void 0;
289 if (oldSortKey != newSortKey) {
290 mapSet(changedSortKeys, rowId, newSortKey);
291 }
292 }
293 };
294 const processTable = (force) => {
295 onChanged(

Callers 1

index.jsFile · 0.70

Calls 1

mapNewFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…