@@ -176,23 +176,13 @@ The general concept of normalized state can be found in [Normalizing State Shape
176176with the following features:
177177
1781781 . ClassState: the state of the class, including the nodes and the root of the class.
179- 2 . NodeState: the state of a node, including the id, children, parent, links of the node, and the content (state) of the node.
179+ 2 . NodeState: the state of a node, including the id of the node and the content (state) of the node.
1801803 . State: the content of the node, represented as a state.
181- 4 . The concept of "parent" and "children" and "links" is embedded in the NodeState.
182- * remove (me):
183- - initiate "remove" for all the children.
184- - remove from the parent.
185- - remove from all the links.
186- * remove child:
187- - the child initiate "remove".
188- * remove link:
189- - the link initiate "remove link" on me.
190- 4 . To avoid complication, currently there is only 1 parent.
191181
192182For example, the example [ in the redux link] ( https://redux.js.org/recipes/structuring-reducers/normalizing-state-shape ) is represented as:
193183
194184``` ts
195- statePost = {
185+ classStatePost = {
196186 myClass: ' post' ,
197187 doMe: (DispatchedAction < Post > ),
198188 nodes: {
@@ -201,33 +191,15 @@ statePost = {
201191 state: {
202192 author : uuid - user1 ,
203193 body : " ......" ,
194+ comments: [uuid - comment1 , uuid - comment2 ]
204195 },
205- _parent: {
206- id: uuid - user1 ,
207- do: doUser
208- },
209- _links: {
210- comment : {
211- list: [uuid - comment1 , uuid - comment2 ],
212- do: doComment
213- }
214- }
215196 },
216197 [uuid - post2 ] : {
217198 id : uuid - post2 ,
218199 state: {
219200 author : uuid - user2 ,
220201 body : " ......" ,
221- },
222- _parent: {
223- id: uuid - user2 ,
224- do: doUser
225- },
226- _links: {
227- comment : {
228- list: [uuid - comment3 , uuid - comment4 , uuid - comment5 ],
229- do: doComment
230- }
202+ comments: [uuid - comment3 , uuid - comment4 , uuid - comment5 ]
231203 }
232204 }
233205 }
@@ -237,7 +209,7 @@ statePost = {
237209and:
238210
239211``` ts
240- stateComment = {
212+ classStateComment = {
241213 myClass: ' comment' ,
242214 doMe: (DispatchedAction < Comment > ),
243215 nodes: {
@@ -246,93 +218,43 @@ stateComment = {
246218 state: {
247219 author : uuid - user2 ,
248220 comment : " ....." ,
249- },
250- _parent: {
251- id: uuid - user2 ,
252- do: doUser
253- },
254- _links: {
255- post: {
256- list: [uuid - post1 ],
257- do: doPost
258- }
259221 }
260222 },
261223 [uuid - comment2 ] : {
262224 id : uuid - comment2 ,
263225 state: {
264226 author : uuid - user3 ,
265227 comment : " ....." ,
266- },
267- _parent: {
268- id: uuid - user3 ,
269- do: doUser
270- },
271- _links: {
272- post: {
273- list: [uuid - post1 ],
274- do: doPost
275- }
276228 }
277229 },
278230 [uuid - comment3 ] : {
279231 id : uuid - comment3 ,
280232 state: {
281233 author : uuid - user3 ,
282234 comment : " ....." ,
283- },
284- _parent: {
285- id: uuid - user3 ,
286- do: doUser
287- },
288- _links: {
289- post: {
290- list: [uuid - post2 ],
291- do: doPost
292- }
293235 }
294236 },
295237 [uuid - comment4 ] : {
296238 id : uuid - comment4 ,
297239 state: {
298240 author : uuid - user1 ,
299241 comment : " ....." ,
300- },
301- _parent: {
302- id: uuid - user1 ,
303- do: doUser
304- },
305- _links: {
306- post: {
307- list: [uuid - post2 ],
308- do: doPost
309- }
310242 }
311243 },
312244 [uuid - comment5 ] : {
313245 id : uuid - comment5 ,
314246 state: {
315247 author : uuid - user3 ,
316248 comment : " ....." ,
317- },
318- _parent: {
319- id: uuid - user3 ,
320- do: doUser
321- },
322- _links: {
323- post: {
324- list: [uuid - post2 ],
325- do: doPost
326- }
327249 }
328- },
250+ }
329251 }
330252}
331253```
332254
333255and:
334256``` ts
335- stateUser = {
257+ classStateUser = {
336258 myClass: ' user' ,
337259 doMe: (DispatchedAction < User > ),
338260 nodes: {
@@ -341,50 +263,20 @@ stateUser = {
341263 state: {
342264 username : " user1" ,
343265 name : " User 1" ,
344- },
345- _children: {
346- post: {
347- list: [uuid - post1 ],
348- do: doPost ,
349- },
350- comment: {
351- list: [uuid - comment4 ],
352- do: doComment ,
353- }
354266 }
355267 },
356268 [uuid - user2 ] : {
357269 id: uuid - user2 ,
358270 state: {
359271 username : " user2" ,
360272 name : " User 2" ,
361- },
362- _children: {
363- post: {
364- list: [uuid - post2 ],
365- do: doPost ,
366- },
367- comment: {
368- list: [uuid - comment1 ],
369- do: doComment ,
370- }
371273 }
372274 },
373275 [uuid - user3 ] : {
374276 id: uuid - user3 ,
375277 state: {
376278 username : " user3" ,
377279 name : " User 3" ,
378- },
379- _children: {
380- post: {
381- list: [uuid - post1 ],
382- do: doPost ,
383- },
384- comment: {
385- list: [uuid - comment2 , uuid - comment3 , uuid - comment5 ],
386- do: doComment ,
387- }
388280 }
389281 }
390282 }
0 commit comments