Skip to content

Commit fd80162

Browse files
committed
docs(www): use code blocks for code snippets pt.2
1 parent d7798ff commit fd80162

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

projects/www/src/app/pages/guide/signals/signal-store/entity-management.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,41 +80,59 @@ export const TodosStore = signalStore(
8080
Adds an entity to the collection.
8181
If 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
8486
patchState(store, addEntity(todo));
8587
```
8688

89+
</ngrx-code-example>
90+
8791
### `addEntities`
8892

8993
Adds multiple entities to the collection.
9094
If 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
9399
patchState(store, addEntities([todo1, todo2]));
94100
```
95101

102+
</ngrx-code-example>
103+
96104
### `prependEntity`
97105

98106
Adds an entity to the beginning of the collection.
99107
If 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
102112
patchState(store, prependEntity(todo));
103113
```
104114

115+
</ngrx-code-example>
116+
105117
### `prependEntities`
106118

107119
Adds multiple entities to the beginning of the collection, maintaining their relative order.
108120
If 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
111125
patchState(store, prependEntities([todo1, todo2]));
112126
```
113127

128+
</ngrx-code-example>
129+
114130
### `updateEntity`
115131

116132
Updates 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
119137
patchState(
120138
store,
@@ -130,10 +148,14 @@ patchState(
130148
);
131149
```
132150

151+
</ngrx-code-example>
152+
133153
### `updateEntities`
134154

135155
Updates 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
139161
patchState(
@@ -167,10 +189,14 @@ patchState(
167189
);
168190
```
169191

192+
</ngrx-code-example>
193+
170194
### `updateAllEntities`
171195

172196
Updates 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
175201
patchState(store, updateAllEntities({ text: '' }));
176202

@@ -180,64 +206,92 @@ patchState(
180206
);
181207
```
182208

209+
</ngrx-code-example>
210+
183211
### `setEntity`
184212

185213
Adds or replaces an entity in the collection.
186214

215+
<ngrx-code-example>
216+
187217
```ts
188218
patchState(store, setEntity(todo));
189219
```
190220

221+
</ngrx-code-example>
222+
191223
### `setEntities`
192224

193225
Adds or replaces multiple entities in the collection.
194226

227+
<ngrx-code-example>
228+
195229
```ts
196230
patchState(store, setEntities([todo1, todo2]));
197231
```
198232

233+
</ngrx-code-example>
234+
199235
### `setAllEntities`
200236

201237
Replaces the current entity collection with the provided collection.
202238

239+
<ngrx-code-example>
240+
203241
```ts
204242
patchState(store, setAllEntities([todo1, todo2, todo3]));
205243
```
206244

245+
</ngrx-code-example>
246+
207247
### `upsertEntity`
208248

209249
Adds or updates an entity in the collection.
210250
When updating, it does not replace the existing entity but merges it with the provided one.
211251
Only the properties provided in the updated entity are merged with the existing entity.
212252
Properties not present in the updated entity remain unchanged.
213253

254+
<ngrx-code-example>
255+
214256
```ts
215257
patchState(store, upsertEntity(todo));
216258
```
217259

260+
</ngrx-code-example>
261+
218262
### `upsertEntities`
219263

220264
Adds or updates multiple entities in the collection.
221265
When updating, it does not replace existing entities but merges them with the provided ones.
222266
Only the properties provided in updated entities are merged with existing entities.
223267
Properties not present in updated entities remain unchanged.
224268

269+
<ngrx-code-example>
270+
225271
```ts
226272
patchState(store, upsertEntities([todo1, todo2]));
227273
```
228274

275+
</ngrx-code-example>
276+
229277
### `removeEntity`
230278

231279
Removes 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
234284
patchState(store, removeEntity(1));
235285
```
236286

287+
</ngrx-code-example>
288+
237289
### `removeEntities`
238290

239291
Removes 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
243297
patchState(store, removeEntities([1, 2]));
@@ -249,14 +303,20 @@ patchState(
249303
);
250304
```
251305

306+
</ngrx-code-example>
307+
252308
### `removeAllEntities`
253309

254310
Removes all entities from the collection. No error is thrown if entities don't exist.
255311

312+
<ngrx-code-example>
313+
256314
```ts
257315
patchState(store, removeAllEntities());
258316
```
259317

318+
</ngrx-code-example>
319+
260320
## Custom Entity Identifier
261321

262322
If an entity doesn't have an identifier named `id`, a custom ID selector should be used.

0 commit comments

Comments
 (0)