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

Function yMapMatch

src/persisters/persister-yjs/index.ts:160–186  ·  view source on GitHub ↗
(
  yMapOrParent: YMap<any>,
  idInParent: Id | undefined,
  obj: IdObj<any>,
  set: (yMap: YMap<any>, id: Id, value: any) => 1 | void,
)

Source from the content-addressed store, hash-verified

158};
159
160const yMapMatch = (
161 yMapOrParent: YMap<any>,
162 idInParent: Id | undefined,
163 obj: IdObj<any>,
164 set: (yMap: YMap<any>, id: Id, value: any) => 1 | void,
165): 1 | void => {
166 const yMap = isUndefined(idInParent)
167 ? yMapOrParent
168 : (yMapOrParent.get(idInParent) ??
169 yMapOrParent.set(idInParent, new YMap()));
170 let changed: 1 | undefined;
171 objMap(obj, (value, id) => {
172 if (set(yMap, id, value)) {
173 changed = 1;
174 }
175 });
176 yMap.forEach((_: any, id: Id) => {
177 if (!objHas(obj, id)) {
178 yMap.delete(id);
179 changed = 1;
180 }
181 });
182 if (!isUndefined(idInParent) && !yMap.size) {
183 yMapOrParent.delete(idInParent);
184 }
185 return changed;
186};
187
188export const createYjsPersister = ((
189 store: Store,

Callers 1

applyChangesToYDocFunction · 0.70

Calls 6

isUndefinedFunction · 0.90
objMapFunction · 0.90
objHasFunction · 0.90
setFunction · 0.85
getMethod · 0.80
deleteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…