@@ -80,41 +80,59 @@ export const TodosStore = signalStore(
8080Adds an entity to the collection.
8181If the entity collection has an entity with the same ID, it is not overridden and no error is thrown.
8282
83+ <ngrx-code-example >
84+
8385``` ts
8486patchState (store , addEntity (todo ));
8587```
8688
89+ </ngrx-code-example >
90+
8791### ` addEntities `
8892
8993Adds multiple entities to the collection.
9094If the entity collection has entities with the same IDs, they are not overridden and no error is thrown.
9195
96+ <ngrx-code-example >
97+
9298``` ts
9399patchState (store , addEntities ([todo1 , todo2 ]));
94100```
95101
102+ </ngrx-code-example >
103+
96104### ` prependEntity `
97105
98106Adds an entity to the beginning of the collection.
99107If the entity collection has an entity with the same ID, it is not added and no error is thrown.
100108
109+ <ngrx-code-example >
110+
101111``` ts
102112patchState (store , prependEntity (todo ));
103113```
104114
115+ </ngrx-code-example >
116+
105117### ` prependEntities `
106118
107119Adds multiple entities to the beginning of the collection, maintaining their relative order.
108120If the entity collection has entities with the same IDs, they are not added and no error is thrown.
109121
122+ <ngrx-code-example >
123+
110124``` ts
111125patchState (store , prependEntities ([todo1 , todo2 ]));
112126```
113127
128+ </ngrx-code-example >
129+
114130### ` updateEntity `
115131
116132Updates an entity in the collection by ID. Supports partial updates. No error is thrown if an entity doesn't exist.
117133
134+ <ngrx-code-example >
135+
118136``` ts
119137patchState (
120138 store ,
@@ -130,10 +148,14 @@ patchState(
130148);
131149```
132150
151+ </ngrx-code-example >
152+
133153### ` updateEntities `
134154
135155Updates multiple entities in the collection by IDs or predicate. Supports partial updates. No error is thrown if entities don't exist.
136156
157+ <ngrx-code-example >
158+
137159``` ts
138160// update entities by IDs
139161patchState (
@@ -167,10 +189,14 @@ patchState(
167189);
168190```
169191
192+ </ngrx-code-example >
193+
170194### ` updateAllEntities `
171195
172196Updates all entities in the collection. Supports partial updates. No error is thrown if entities don't exist.
173197
198+ <ngrx-code-example >
199+
174200``` ts
175201patchState (store , updateAllEntities ({ text: ' ' }));
176202
@@ -180,64 +206,92 @@ patchState(
180206);
181207```
182208
209+ </ngrx-code-example >
210+
183211### ` setEntity `
184212
185213Adds or replaces an entity in the collection.
186214
215+ <ngrx-code-example >
216+
187217``` ts
188218patchState (store , setEntity (todo ));
189219```
190220
221+ </ngrx-code-example >
222+
191223### ` setEntities `
192224
193225Adds or replaces multiple entities in the collection.
194226
227+ <ngrx-code-example >
228+
195229``` ts
196230patchState (store , setEntities ([todo1 , todo2 ]));
197231```
198232
233+ </ngrx-code-example >
234+
199235### ` setAllEntities `
200236
201237Replaces the current entity collection with the provided collection.
202238
239+ <ngrx-code-example >
240+
203241``` ts
204242patchState (store , setAllEntities ([todo1 , todo2 , todo3 ]));
205243```
206244
245+ </ngrx-code-example >
246+
207247### ` upsertEntity `
208248
209249Adds or updates an entity in the collection.
210250When updating, it does not replace the existing entity but merges it with the provided one.
211251Only the properties provided in the updated entity are merged with the existing entity.
212252Properties not present in the updated entity remain unchanged.
213253
254+ <ngrx-code-example >
255+
214256``` ts
215257patchState (store , upsertEntity (todo ));
216258```
217259
260+ </ngrx-code-example >
261+
218262### ` upsertEntities `
219263
220264Adds or updates multiple entities in the collection.
221265When updating, it does not replace existing entities but merges them with the provided ones.
222266Only the properties provided in updated entities are merged with existing entities.
223267Properties not present in updated entities remain unchanged.
224268
269+ <ngrx-code-example >
270+
225271``` ts
226272patchState (store , upsertEntities ([todo1 , todo2 ]));
227273```
228274
275+ </ngrx-code-example >
276+
229277### ` removeEntity `
230278
231279Removes an entity from the collection by ID. No error is thrown if an entity doesn't exist.
232280
281+ <ngrx-code-example >
282+
233283``` ts
234284patchState (store , removeEntity (1 ));
235285```
236286
287+ </ngrx-code-example >
288+
237289### ` removeEntities `
238290
239291Removes multiple entities from the collection by IDs or predicate. No error is thrown if entities don't exist.
240292
293+ <ngrx-code-example >
294+
241295``` ts
242296// remove entities by IDs
243297patchState (store , removeEntities ([1 , 2 ]));
@@ -249,14 +303,20 @@ patchState(
249303);
250304```
251305
306+ </ngrx-code-example >
307+
252308### ` removeAllEntities `
253309
254310Removes all entities from the collection. No error is thrown if entities don't exist.
255311
312+ <ngrx-code-example >
313+
256314``` ts
257315patchState (store , removeAllEntities ());
258316```
259317
318+ </ngrx-code-example >
319+
260320## Custom Entity Identifier
261321
262322If an entity doesn't have an identifier named ` id ` , a custom ID selector should be used.
0 commit comments