Skip to content

Commit 1cfdd2c

Browse files
committed
docs: Update entity lifecycle to include delegate.mergeEntity
1 parent 9f79b6e commit 1cfdd2c

File tree

5 files changed

+211
-5
lines changed

5 files changed

+211
-5
lines changed

docs/graphql/diagrams/_entity_lifecycle.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ flowchart BT
1717
pk---validate("Entity.validate()")
1818
process-->validate
1919
validate---normNest("normalize(this.schema)")
20+
normNest-->mergeEntity("delegate.mergeEntity()")
2021
end
2122
Entity.normalize--processedEntity-->INSTORE
2223
subgraph INSTORE["Found In Store"]

docs/rest/diagrams/_entity_lifecycle.mdx

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ flowchart BT
1717
pk---validate("Entity.validate()")
1818
process-->validate
1919
validate---normNest("normalize(this.schema)")
20+
normNest-->mergeEntity("delegate.mergeEntity()")
2021
end
2122
Entity.normalize--processedEntity-->INSTORE
2223
subgraph INSTORE["Found In Store"]

jest.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const projects = [
8383
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.node\\.(j|t)sx?$',
8484
},
8585
{
86-
// RN preset at https://github.com/facebook/react-native/blob/main/jest-preset.js
86+
// RN preset at https://github.com/facebook/react-native/blob/main/packages/react-native/jest-preset.js
8787
...baseConfig,
8888
rootDir: __dirname,
8989
roots: packages.map(pkgName => `<rootDir>/packages/${pkgName}/src`),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// import {
2+
// EntityTable,
3+
// NormalizedIndex,
4+
// INormalizeDelegate,
5+
// Mergeable,
6+
// } from '../interface.js';
7+
// import { getCheckLoop } from './getCheckLoop.js';
8+
// import { INVALID } from '../denormalize/symbol.js';
9+
// import { DelegateImmutable } from '../memo/Delegate.immutable.js';
10+
11+
// type ImmutableJSEntityTable = {
12+
// getIn(k: [key: string, pk: string]): { toJS(): any } | undefined;
13+
// setIn(k: [key: string, pk: string], value: any);
14+
// };
15+
// type ImmutableJSMeta = {
16+
// getIn(k: [key: string, pk: string]):
17+
// | {
18+
// date: number;
19+
// expiresAt: number;
20+
// fetchedAt: number;
21+
// }
22+
// | undefined;
23+
// setIn(
24+
// k: [key: string, pk: string],
25+
// value: {
26+
// date: number;
27+
// expiresAt: number;
28+
// fetchedAt: number;
29+
// },
30+
// );
31+
// };
32+
33+
// export class NormalizeDelegate
34+
// extends DelegateImmutable
35+
// implements INormalizeDelegate
36+
// {
37+
// declare readonly entitiesMeta: ImmutableJSMeta;
38+
39+
// declare readonly meta: { fetchedAt: number; date: number; expiresAt: number };
40+
// declare checkLoop: (entityKey: string, pk: string, input: object) => boolean;
41+
42+
// protected newEntities = new Map<string, Map<string, any>>();
43+
// protected newIndexes = new Map<string, Map<string, any>>();
44+
45+
// constructor(
46+
// {
47+
// entities,
48+
// indexes,
49+
// entitiesMeta,
50+
// }: {
51+
// entities: ImmutableJSEntityTable;
52+
// indexes: ImmutableJSEntityTable;
53+
// entitiesMeta: ImmutableJSMeta;
54+
// },
55+
// actionMeta: { fetchedAt: number; date: number; expiresAt: number },
56+
// ) {
57+
// super(entities, indexes);
58+
// this.entitiesMeta = entitiesMeta;
59+
// this.meta = actionMeta;
60+
// this.checkLoop = getCheckLoop();
61+
// }
62+
63+
// // getNewEntity(key: string, pk: string) {
64+
// // return this.getNewEntities(key).get(pk);
65+
// // }
66+
67+
// protected getNewEntities(key: string): Map<string, any> {
68+
// // first time we come across this type of entity
69+
// if (!this.newEntities.has(key)) {
70+
// this.newEntities.set(key, new Map());
71+
// }
72+
73+
// return this.newEntities.get(key) as Map<string, any>;
74+
// }
75+
76+
// protected getNewIndexes(key: string): Map<string, any> {
77+
// if (!this.newIndexes.has(key)) {
78+
// this.newIndexes.set(key, new Map());
79+
// }
80+
// return this.newIndexes.get(key) as Map<string, any>;
81+
// }
82+
83+
// // /** Updates an entity using merge lifecycles when it has previously been set */
84+
// // mergeEntity(
85+
// // schema: Mergeable & { indexes?: any },
86+
// // pk: string,
87+
// // incomingEntity: any,
88+
// // ) {
89+
// // const key = schema.key;
90+
91+
// // // default when this is completely new entity
92+
// // let nextEntity = incomingEntity;
93+
// // let nextMeta = this.meta;
94+
95+
// // // if we already processed this entity during this normalization (in another nested place)
96+
// // let entity = this.getNewEntity(key, pk);
97+
// // if (entity) {
98+
// // nextEntity = schema.merge(entity, incomingEntity);
99+
// // } else {
100+
// // // if we find it in the store
101+
// // entity = this.getEntity(key, pk);
102+
// // if (entity) {
103+
// // const meta = this.getMeta(key, pk);
104+
// // nextEntity = schema.mergeWithStore(
105+
// // meta,
106+
// // nextMeta,
107+
// // entity,
108+
// // incomingEntity,
109+
// // );
110+
// // nextMeta = schema.mergeMetaWithStore(
111+
// // meta,
112+
// // nextMeta,
113+
// // entity,
114+
// // incomingEntity,
115+
// // );
116+
// // }
117+
// // }
118+
119+
// // // once we have computed the merged values, set them
120+
// // this.setEntity(schema, pk, nextEntity, nextMeta);
121+
// // }
122+
123+
// /** Sets an entity overwriting any previously set values */
124+
// setEntity(
125+
// schema: { key: string; indexes?: any },
126+
// pk: string,
127+
// entity: any,
128+
// meta: { fetchedAt: number; date: number; expiresAt: number } = this.meta,
129+
// ) {
130+
// const key = schema.key;
131+
// const newEntities = this.getNewEntities(key);
132+
// const updateMeta = !newEntities.has(pk);
133+
// newEntities.set(pk, entity);
134+
135+
// // update index
136+
// if (schema.indexes) {
137+
// handleIndexes(
138+
// pk,
139+
// schema.indexes,
140+
// this.getNewIndexes(key),
141+
// this.indexes[key],
142+
// entity,
143+
// this.entities[key] as any,
144+
// );
145+
// }
146+
147+
// // set this after index updates so we know what indexes to remove from
148+
// (this.entities[key] as any)[pk] = entity;
149+
150+
// if (updateMeta) this.entitiesMeta[key][pk] = meta;
151+
// }
152+
153+
// protected _setEntity(key: string, pk: string, entity: any) {
154+
// this.entities.setIn([key, pk], entity);
155+
// }
156+
157+
// protected _setMeta(
158+
// key: string,
159+
// pk: string,
160+
// meta: { fetchedAt: number; date: number; expiresAt: number },
161+
// ) {
162+
// this.entitiesMeta.setIn([key, pk], meta);
163+
// }
164+
165+
// getMeta(key: string, pk: string) {
166+
// return this.entitiesMeta.getIn([key, pk]);
167+
// }
168+
// }
169+
170+
// function handleIndexes(
171+
// id: string,
172+
// schemaIndexes: string[],
173+
// indexes: Map<string, any>,
174+
// storeIndexes: Record<string, any>,
175+
// entity: any,
176+
// storeEntities: Record<string, any>,
177+
// ) {
178+
// for (const index of schemaIndexes) {
179+
// if (!indexes.has(index)) {
180+
// indexes.set(index, (storeIndexes[index] = {}));
181+
// }
182+
// const indexMap = indexes.get(index);
183+
// if (storeEntities[id]) {
184+
// delete indexMap[storeEntities[id][index]];
185+
// }
186+
// // entity already in cache but the index changed
187+
// if (
188+
// storeEntities &&
189+
// storeEntities[id] &&
190+
// storeEntities[id][index] !== entity[index]
191+
// ) {
192+
// indexMap[storeEntities[id][index]] = INVALID;
193+
// }
194+
// if (index in entity) {
195+
// indexMap[entity[index]] = id;
196+
// } /* istanbul ignore next */ else if (
197+
// process.env.NODE_ENV !== 'production'
198+
// ) {
199+
// console.warn(`Index not found in entity. Indexes must be top-level members of your entity.
200+
// Index: ${index}
201+
// Entity: ${JSON.stringify(entity, undefined, 2)}`);
202+
// }
203+
// }
204+
// }

website/blog/tags.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ nextjs:
1818
description: 'NextJS is an SSR and SSG framework for ReactJS'
1919
permalink: /nextjs
2020

21-
expogo:
22-
label: 'ExpoGo'
23-
description: 'ExpoGo is a React Native framework'
24-
permalink: /expogo
21+
expo:
22+
label: 'Expo'
23+
description: 'Expo (and ExpoGo) is a React Native framework'
24+
permalink: /expo
2525

2626
native:
2727
label: 'React Native'

0 commit comments

Comments
 (0)