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

Function setRelationshipDefinition

src/relationships/index.ts:102–180  ·  view source on GitHub ↗
(
      relationshipId: Id,
      localTableId: Id,
      remoteTableId: Id,
      getRemoteRowId: Id | ((getCell: GetCell, localRowId: Id) => Id),
    )

Source from the content-addressed store, hash-verified

100 );
101
102 const setRelationshipDefinition = (
103 relationshipId: Id,
104 localTableId: Id,
105 remoteTableId: Id,
106 getRemoteRowId: Id | ((getCell: GetCell, localRowId: Id) => Id),
107 ): Relationships => {
108 mapSet(remoteTableIds, relationshipId, remoteTableId);
109
110 setDefinitionAndListen(
111 relationshipId,
112 localTableId,
113 (
114 change: () => void,
115 changedRemoteRowIds: IdMap<[Id | undefined, Id | undefined]>,
116 ) => {
117 const changedLocalRows: IdSet = setNew();
118 const changedRemoteRows: IdSet = setNew();
119 const changedLinkedRows: IdSet = setNew();
120 const [localRows, remoteRows] = getRelationship(
121 relationshipId,
122 ) as Relationship;
123
124 collForEach(
125 changedRemoteRowIds,
126 ([oldRemoteRowId, newRemoteRowId], localRowId) => {
127 if (!isUndefined(oldRemoteRowId)) {
128 setAdd(changedRemoteRows, oldRemoteRowId);
129 ifNotUndefined(
130 mapGet(remoteRows, oldRemoteRowId),
131 (oldRemoteRow) => {
132 collDel(oldRemoteRow, localRowId);
133 if (collIsEmpty(oldRemoteRow)) {
134 mapSet(remoteRows, oldRemoteRowId);
135 }
136 },
137 );
138 }
139 if (!isUndefined(newRemoteRowId)) {
140 setAdd(changedRemoteRows, newRemoteRowId);
141 if (!collHas(remoteRows, newRemoteRowId)) {
142 mapSet(remoteRows, newRemoteRowId, setNew());
143 }
144 setAdd(mapGet(remoteRows, newRemoteRowId), localRowId);
145 }
146 setAdd(changedLocalRows, localRowId);
147 mapSet(localRows, localRowId, newRemoteRowId);
148 mapForEach(
149 mapGet(linkedRowIdsListeners, relationshipId),
150 (firstRowId) => {
151 if (
152 collHas(
153 getLinkedRowIdsCache(relationshipId, firstRowId),
154 localRowId,
155 )
156 ) {
157 setAdd(changedLinkedRows, firstRowId);
158 }
159 },

Callers

nothing calls this directly

Calls 15

mapSetFunction · 0.90
setNewFunction · 0.90
collForEachFunction · 0.90
isUndefinedFunction · 0.90
setAddFunction · 0.90
mapGetFunction · 0.90
collDelFunction · 0.90
collIsEmptyFunction · 0.90
collHasFunction · 0.90
mapForEachFunction · 0.90
getRowCellFunctionFunction · 0.90
getLinkedRowIdsCacheFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…