@fireflysemantics/slice 17.0.14 → 17.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/esm2022/lib/AbstractStore.mjs +17 -14
- package/esm2022/lib/EStore.mjs +203 -139
- package/esm2022/lib/Slice.mjs +10 -10
- package/fesm2022/fireflysemantics-slice.mjs +227 -160
- package/fesm2022/fireflysemantics-slice.mjs.map +1 -1
- package/lib/AbstractStore.d.ts +16 -13
- package/lib/EStore.d.ts +182 -116
- package/lib/Slice.d.ts +9 -9
- package/package.json +1 -1
@@ -256,10 +256,10 @@ class AbstractStore {
|
|
256
256
|
* @param p The predicate used to query for the selection.
|
257
257
|
* @return A snapshot array containing the entities that match the predicate.
|
258
258
|
*
|
259
|
-
* @example Select all the
|
260
|
-
|
261
|
-
|
262
|
-
|
259
|
+
* @example Select all the Todo instances where the title length is greater than 100.
|
260
|
+
* ```
|
261
|
+
* let todos:Todo[]=store.select(todo=>todo.title.length>100);
|
262
|
+
* ```
|
263
263
|
*/
|
264
264
|
select(p) {
|
265
265
|
const selected = [];
|
@@ -275,10 +275,11 @@ class AbstractStore {
|
|
275
275
|
* @param e1 The first entity
|
276
276
|
* @param e2 The second entity
|
277
277
|
* @return true if the two entities have equal GUID ids
|
278
|
-
*
|
279
|
-
|
280
|
-
|
281
|
-
|
278
|
+
*
|
279
|
+
* @example Compare todo1 with todo2 by gid.
|
280
|
+
* ```
|
281
|
+
* if (equalsByGUID(todo1, todo2)){...};
|
282
|
+
* ```
|
282
283
|
*/
|
283
284
|
equalsByGUID(e1, e2) {
|
284
285
|
return e1[this.GUID_KEY] == e2[this.GUID_KEY];
|
@@ -288,16 +289,18 @@ class AbstractStore {
|
|
288
289
|
* @param e1 The first entity
|
289
290
|
* @param e2 The second entity
|
290
291
|
* @return true if the two entities have equal ID ids
|
291
|
-
*
|
292
|
-
|
293
|
-
|
294
|
-
|
292
|
+
*
|
293
|
+
* @example Compare todo1 with todo2 by id.
|
294
|
+
*
|
295
|
+
* ```
|
296
|
+
* if (equalsByID(todo1, todo2)){...};
|
297
|
+
* ```
|
295
298
|
*/
|
296
299
|
equalsByID(e1, e2) {
|
297
300
|
return e1[this.ID_KEY] == e2[this.ID_KEY];
|
298
301
|
}
|
299
302
|
/**
|
300
|
-
* Calls complete on all {@link
|
303
|
+
* Calls complete on all {@link ReplaySubject} instances.
|
301
304
|
*
|
302
305
|
* Call destroy when disposing of the store.
|
303
306
|
*/
|
@@ -542,15 +545,15 @@ class Slice extends AbstractStore {
|
|
542
545
|
* @param eStore The EStore instance containing the elements considered for slicing
|
543
546
|
*
|
544
547
|
* @example
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
548
|
+
* ```
|
549
|
+
* //Empty slice
|
550
|
+
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete);
|
551
|
+
*
|
552
|
+
* //Initialized slice
|
553
|
+
* let todos = [new Todo(false, "You complete me!"),
|
554
|
+
* new Todo(true, "You completed me!")];
|
555
|
+
* new Slice<Todo>(Todo.COMPLETE, todo=>!todo.complete, todos);
|
556
|
+
* ```
|
554
557
|
*/
|
555
558
|
constructor(label, predicate, eStore) {
|
556
559
|
super();
|
@@ -755,36 +758,43 @@ class Slice extends AbstractStore {
|
|
755
758
|
* This `todoFactory` code will be used to illustrate the API examples. The following
|
756
759
|
* utilities are used in the tests and the API Typedoc examples contained here.
|
757
760
|
* @example Utilities for API Examples
|
758
|
-
```
|
759
|
-
export const enum TodoSliceEnum {
|
760
|
-
|
761
|
-
|
762
|
-
}
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
761
|
+
* ```
|
762
|
+
* export const enum TodoSliceEnum {
|
763
|
+
* COMPLETE = "Complete",
|
764
|
+
* INCOMPLETE = "Incomplete"
|
765
|
+
* }
|
766
|
+
* export class Todo {
|
767
|
+
* constructor(
|
768
|
+
* public complete: boolean,
|
769
|
+
* public title: string,
|
770
|
+
* public gid?:string,
|
771
|
+
* public id?:string) {}
|
772
|
+
* }
|
773
|
+
*
|
774
|
+
* export let todos = [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
|
775
|
+
*
|
776
|
+
* export function todosFactory():Todo[] {
|
777
|
+
* return [new Todo(false, "You complete me!"), new Todo(true, "You completed me!")];
|
778
|
+
* }
|
779
|
+
* ```
|
774
780
|
*/
|
775
781
|
class EStore extends AbstractStore {
|
776
782
|
/**
|
777
783
|
* Store constructor (Initialization with element is optional)
|
778
784
|
*
|
779
785
|
* perform initial notification to all observers,
|
780
|
-
* such that
|
786
|
+
* such that functions like {@link combineLatest}{}
|
781
787
|
* will execute at least once.
|
782
|
-
*
|
783
|
-
* @
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
+
*
|
789
|
+
* @param entities The entities to initialize the store with.
|
790
|
+
* @param config The optional configuration instance.
|
791
|
+
*
|
792
|
+
* @example EStore<Todo> Creation
|
793
|
+
* ```
|
794
|
+
* // Initialize the Store
|
795
|
+
* let store: EStore<Todo> = new EStore<Todo>(todosFactory());
|
796
|
+
* ```
|
797
|
+
*/
|
788
798
|
constructor(entities = [], config) {
|
789
799
|
super(config);
|
790
800
|
/**
|
@@ -839,7 +849,7 @@ class EStore extends AbstractStore {
|
|
839
849
|
this.notifyDelta.next(delta);
|
840
850
|
}
|
841
851
|
/**
|
842
|
-
* Calls complete on all {@link
|
852
|
+
* Calls complete on all EStore {@link ReplaySubject} instances.
|
843
853
|
*
|
844
854
|
* Call destroy when disposing of the store.
|
845
855
|
*/
|
@@ -847,7 +857,7 @@ class EStore extends AbstractStore {
|
|
847
857
|
super.destroy();
|
848
858
|
this.notifyLoading.complete();
|
849
859
|
this.notifyActive.complete();
|
850
|
-
this.slices.forEach(slice => slice.destroy());
|
860
|
+
this.slices.forEach((slice) => slice.destroy());
|
851
861
|
}
|
852
862
|
/**
|
853
863
|
* Toggles the entity:
|
@@ -856,16 +866,15 @@ class EStore extends AbstractStore {
|
|
856
866
|
* it will be deleted. If the store
|
857
867
|
* does not contains the entity,
|
858
868
|
* it is added.
|
859
|
-
* @param e
|
860
|
-
* @example Toggle the
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
```
|
869
|
+
* @param e The entity to toggle
|
870
|
+
* @example Toggle the Todo instance
|
871
|
+
* ```
|
872
|
+
* estore.post(todo);
|
873
|
+
* // Remove todo
|
874
|
+
* estore.toggle(todo);
|
875
|
+
* // Add it back
|
876
|
+
* estore.toggle(todo);
|
877
|
+
* ```
|
869
878
|
*/
|
870
879
|
toggle(e) {
|
871
880
|
if (this.contains(e)) {
|
@@ -886,11 +895,11 @@ class EStore extends AbstractStore {
|
|
886
895
|
* change detection in the event that it maintains
|
887
896
|
* a reference to the `active` state `Map` instance.
|
888
897
|
*
|
889
|
-
* @example Add
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
898
|
+
* @example Add todo1 and todo2 as active
|
899
|
+
* ```
|
900
|
+
* addActive(todo1);
|
901
|
+
* addActive(todo2);
|
902
|
+
* ```
|
894
903
|
*/
|
895
904
|
addActive(e) {
|
896
905
|
if (this.contains(e)) {
|
@@ -904,18 +913,18 @@ class EStore extends AbstractStore {
|
|
904
913
|
}
|
905
914
|
}
|
906
915
|
/**
|
907
|
-
* Delete an entity
|
916
|
+
* Delete an active entity.
|
908
917
|
*
|
909
918
|
* Also we clone the map prior to broadcasting it with
|
910
919
|
* `notifyActive` to make sure we will trigger Angular
|
911
920
|
* change detection in the event that it maintains
|
912
921
|
* a reference to the `active` state `Map` instance.
|
913
922
|
*
|
914
|
-
* @example
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
923
|
+
* @example Remove todo1 and todo2 as active entities
|
924
|
+
* ```
|
925
|
+
* deleteActive(todo1);
|
926
|
+
* deleteActive(todo2);
|
927
|
+
* ```
|
919
928
|
*/
|
920
929
|
deleteActive(e) {
|
921
930
|
this.active.delete(e.gid);
|
@@ -929,23 +938,23 @@ class EStore extends AbstractStore {
|
|
929
938
|
* change detection in the event that it maintains
|
930
939
|
* a reference to the `active` state `Map` instance.
|
931
940
|
*
|
932
|
-
* @example
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
```
|
941
|
+
* @example Clear active todo instances
|
942
|
+
* ```
|
943
|
+
* store.clearActive();
|
944
|
+
* ```
|
937
945
|
*/
|
938
946
|
clearActive() {
|
939
947
|
this.active.clear();
|
940
948
|
this.notifyActive.next(new Map(this.active));
|
941
949
|
}
|
942
950
|
/**
|
943
|
-
* Observe the active
|
951
|
+
* Observe the active entities.
|
952
|
+
*
|
944
953
|
* @example
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
954
|
+
* ```
|
955
|
+
* let active$ = store.observeActive();
|
956
|
+
* ```
|
957
|
+
*/
|
949
958
|
observeActive() {
|
950
959
|
return this.notifyActive.asObservable();
|
951
960
|
}
|
@@ -968,35 +977,91 @@ class EStore extends AbstractStore {
|
|
968
977
|
}
|
969
978
|
/**
|
970
979
|
* @return A snapshot of the loading state.
|
980
|
+
* @example Create a reference to the loading state
|
981
|
+
* ```
|
982
|
+
* const loading:boolean = todoStore.loading;
|
983
|
+
* ```
|
971
984
|
*/
|
972
985
|
get loading() {
|
973
986
|
return this._loading;
|
974
987
|
}
|
975
988
|
/**
|
976
989
|
* Observe loading.
|
990
|
+
*
|
991
|
+
* Note that this obverable piped through
|
992
|
+
* `takeWhile(v->v, true), such that it will
|
993
|
+
* complete after each emission.
|
994
|
+
*
|
995
|
+
* See:
|
996
|
+
* https://fireflysemantics.medium.com/waiting-on-estore-to-load-8dcbe161613c
|
997
|
+
*
|
998
|
+
* For more details.
|
999
|
+
* Also note that v=>v is the same as v=>v!=false
|
1000
|
+
*
|
977
1001
|
* @example
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
1002
|
+
* ```
|
1003
|
+
* const observeLoadingHandler: Observer<boolean> = {
|
1004
|
+
* complete: () => {
|
1005
|
+
* console.log(`Data Loaded and Observable Marked as Complete`);
|
1006
|
+
* }, // completeHandler
|
1007
|
+
* error: () => {
|
1008
|
+
* console.log(`Any Errors?`);
|
1009
|
+
* }, // errorHandler
|
1010
|
+
* next: (l) => {
|
1011
|
+
* console.log(`Data loaded and loading is ${l}`);
|
1012
|
+
* },
|
1013
|
+
* };
|
1014
|
+
*
|
1015
|
+
* const observeLoadingResubscribeHandler: Observer<boolean> = {
|
1016
|
+
* complete: () => {
|
1017
|
+
* console.log(`Data Loaded and Resubscribe Observable Marked as Complete`);
|
1018
|
+
* }, // completeHandler
|
1019
|
+
* error: () => {
|
1020
|
+
* console.log(`Any Resubscribe Errors?`);
|
1021
|
+
* }, // errorHandler
|
1022
|
+
* next: (l) => {
|
1023
|
+
* console.log(`Data loaded and resusbscribe loading value is ${l}`);
|
1024
|
+
* },
|
1025
|
+
* };
|
1026
|
+
*
|
1027
|
+
* const todoStore: EStore<Todo> = new EStore();
|
1028
|
+
* //============================================
|
1029
|
+
* // Loading is true by default
|
1030
|
+
* //============================================
|
1031
|
+
* console.log(`The initial value of loading is ${todoStore.loading}`);
|
1032
|
+
* //============================================
|
1033
|
+
* // Observe Loading
|
1034
|
+
* //============================================
|
1035
|
+
* let loading$: Observable<boolean> = todoStore.observeLoading();
|
1036
|
+
* loading$.subscribe((l) => console.log(`The value of loading is ${l}`));
|
1037
|
+
*
|
1038
|
+
* todoStore.loading = false;
|
1039
|
+
* loading$.subscribe(observeLoadingHandler);
|
1040
|
+
* //============================================
|
1041
|
+
* // The subscription no longer fires
|
1042
|
+
* //============================================
|
1043
|
+
* todoStore.loading = true;
|
1044
|
+
* todoStore.loading = false;
|
1045
|
+
*
|
1046
|
+
* //============================================
|
1047
|
+
* // The subscription no longer fires,
|
1048
|
+
* // so if we want to observe loading again
|
1049
|
+
* // resusbscribe.
|
1050
|
+
* //============================================
|
1051
|
+
* todoStore.loading = true;
|
1052
|
+
* loading$ = todoStore.observeLoading();
|
1053
|
+
* loading$.subscribe(observeLoadingResubscribeHandler);
|
1054
|
+
* todoStore.loading = false;
|
1055
|
+
* ```
|
1056
|
+
*/
|
991
1057
|
observeLoading() {
|
992
|
-
return this.notifyLoading.asObservable().
|
993
|
-
pipe(takeWhile(v => v, true));
|
1058
|
+
return this.notifyLoading.asObservable().pipe(takeWhile((v) => v, true));
|
994
1059
|
}
|
995
1060
|
/**
|
996
1061
|
* Notfiies when loading has completed.
|
997
1062
|
*/
|
998
1063
|
observeLoadingComplete() {
|
999
|
-
return this.observeLoading().pipe(filter(loading => loading == false), switchMap(() => of(true)));
|
1064
|
+
return this.observeLoading().pipe(filter((loading) => loading == false), switchMap(() => of(true)));
|
1000
1065
|
}
|
1001
1066
|
/**
|
1002
1067
|
* Sets the current searching state and notifies observers.
|
@@ -1028,14 +1093,13 @@ class EStore extends AbstractStore {
|
|
1028
1093
|
For more details.
|
1029
1094
|
*/
|
1030
1095
|
observeSearching() {
|
1031
|
-
return this.notifySearching.asObservable().
|
1032
|
-
pipe(takeWhile(v => v, true));
|
1096
|
+
return this.notifySearching.asObservable().pipe(takeWhile((v) => v, true));
|
1033
1097
|
}
|
1034
1098
|
/**
|
1035
1099
|
* Notfiies when searching has completed.
|
1036
1100
|
*/
|
1037
1101
|
observeSearchingComplete() {
|
1038
|
-
return this.observeSearching().pipe(filter(searching => searching == false), switchMap(() => of(true)));
|
1102
|
+
return this.observeSearching().pipe(filter((searching) => searching == false), switchMap(() => of(true)));
|
1039
1103
|
}
|
1040
1104
|
/**
|
1041
1105
|
* Adds a slice to the store and keys it by the slices label.
|
@@ -1080,10 +1144,11 @@ class EStore extends AbstractStore {
|
|
1080
1144
|
/**
|
1081
1145
|
* Post (Add a new) element(s) to the store.
|
1082
1146
|
* @param e An indiidual entity or an array of entities
|
1083
|
-
* @example Post a
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1147
|
+
* @example Post a Todo instance.
|
1148
|
+
*
|
1149
|
+
*```
|
1150
|
+
* store.post(todo);
|
1151
|
+
*```
|
1087
1152
|
*/
|
1088
1153
|
post(e) {
|
1089
1154
|
if (!Array.isArray(e)) {
|
@@ -1093,7 +1158,7 @@ class EStore extends AbstractStore {
|
|
1093
1158
|
e[this.GUID_KEY] = guid;
|
1094
1159
|
this.entries.set(guid, e);
|
1095
1160
|
this.updateIDEntry(e);
|
1096
|
-
Array.from(this.slices.values()).forEach(s => {
|
1161
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1097
1162
|
s.post(e);
|
1098
1163
|
});
|
1099
1164
|
//Create a new array reference to trigger Angular change detection.
|
@@ -1106,15 +1171,15 @@ class EStore extends AbstractStore {
|
|
1106
1171
|
}
|
1107
1172
|
}
|
1108
1173
|
/**
|
1109
|
-
* Post
|
1174
|
+
* Post N entities to the store.
|
1110
1175
|
* @param ...e
|
1111
|
-
* @example Post two
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1176
|
+
* @example Post two Todo instances.
|
1177
|
+
* ```
|
1178
|
+
* store.post(todo1, todo2);
|
1179
|
+
* ```
|
1115
1180
|
*/
|
1116
1181
|
postN(...e) {
|
1117
|
-
e.forEach(e => {
|
1182
|
+
e.forEach((e) => {
|
1118
1183
|
const guid = e[this.GUID_KEY]
|
1119
1184
|
? e[this.GUID_KEY]
|
1120
1185
|
: GUID();
|
@@ -1122,7 +1187,7 @@ class EStore extends AbstractStore {
|
|
1122
1187
|
this.entries.set(guid, e);
|
1123
1188
|
this.updateIDEntry(e);
|
1124
1189
|
});
|
1125
|
-
Array.from(this.slices.values()).forEach(s => {
|
1190
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1126
1191
|
s.postA(e);
|
1127
1192
|
});
|
1128
1193
|
//Create a new array reference to trigger Angular change detection.
|
@@ -1133,21 +1198,22 @@ class EStore extends AbstractStore {
|
|
1133
1198
|
/**
|
1134
1199
|
* Post (Add) an array of elements to the store.
|
1135
1200
|
* @param e
|
1136
|
-
* @example Post a
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1201
|
+
* @example Post a Todo array.
|
1202
|
+
*
|
1203
|
+
* ```
|
1204
|
+
* store.post([todo1, todo2]);
|
1205
|
+
* ```
|
1140
1206
|
*/
|
1141
1207
|
postA(e) {
|
1142
1208
|
this.postN(...e);
|
1143
1209
|
}
|
1144
1210
|
/**
|
1145
|
-
* Put (Update) an
|
1211
|
+
* Put (Update) an entity.
|
1146
1212
|
* @param e
|
1147
1213
|
* @example Put a Todo instance.
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1214
|
+
* ```
|
1215
|
+
* store.put(todo1);
|
1216
|
+
* ```
|
1151
1217
|
*/
|
1152
1218
|
put(e) {
|
1153
1219
|
if (!Array.isArray(e)) {
|
@@ -1158,7 +1224,7 @@ class EStore extends AbstractStore {
|
|
1158
1224
|
this.notify.next(v);
|
1159
1225
|
const delta = { type: "Put" /* ActionTypes.PUT */, entries: [e] };
|
1160
1226
|
this.notifyDelta.next(delta);
|
1161
|
-
Array.from(this.slices.values()).forEach(s => {
|
1227
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1162
1228
|
s.put(e);
|
1163
1229
|
});
|
1164
1230
|
}
|
@@ -1169,25 +1235,26 @@ class EStore extends AbstractStore {
|
|
1169
1235
|
/**
|
1170
1236
|
* Put (Update) an element or add an element that was read from a persistence source
|
1171
1237
|
* and thus already has an assigned global id`.
|
1172
|
-
* @param e
|
1173
|
-
* @example Put Todo instances.
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1238
|
+
* @param e The enetity instances to update.
|
1239
|
+
* @example Put N Todo instances.
|
1240
|
+
*
|
1241
|
+
* ```
|
1242
|
+
* store.put(todo1, todo2);
|
1243
|
+
* ```
|
1177
1244
|
*/
|
1178
1245
|
putN(...e) {
|
1179
1246
|
this.putA(e);
|
1180
1247
|
}
|
1181
1248
|
/**
|
1182
|
-
* Put (Update) the array of
|
1183
|
-
* @param e
|
1184
|
-
* @example Put Todo instances.
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1249
|
+
* Put (Update) the array of enntities.
|
1250
|
+
* @param e The array of enntities to update
|
1251
|
+
* @example Put an array of Todo instances.
|
1252
|
+
* ```
|
1253
|
+
* store.put([todo1, todo2]);
|
1254
|
+
* ```
|
1188
1255
|
*/
|
1189
1256
|
putA(e) {
|
1190
|
-
e.forEach(e => {
|
1257
|
+
e.forEach((e) => {
|
1191
1258
|
let guid = e[this.GUID_KEY];
|
1192
1259
|
this.entries.set(guid, e);
|
1193
1260
|
this.updateIDEntry(e);
|
@@ -1197,7 +1264,7 @@ class EStore extends AbstractStore {
|
|
1197
1264
|
this.notify.next(v);
|
1198
1265
|
const delta = { type: "Put" /* ActionTypes.PUT */, entries: e };
|
1199
1266
|
this.notifyDelta.next(delta);
|
1200
|
-
Array.from(this.slices.values()).forEach(s => {
|
1267
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1201
1268
|
s.putA(e);
|
1202
1269
|
});
|
1203
1270
|
}
|
@@ -1205,9 +1272,9 @@ class EStore extends AbstractStore {
|
|
1205
1272
|
* Delete (Update) the array of elements.
|
1206
1273
|
* @param e
|
1207
1274
|
* @example Delete todo1.
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1275
|
+
* ```
|
1276
|
+
* store.delete(todo1]);
|
1277
|
+
* ```
|
1211
1278
|
*/
|
1212
1279
|
delete(e) {
|
1213
1280
|
if (!Array.isArray(e)) {
|
@@ -1215,14 +1282,14 @@ class EStore extends AbstractStore {
|
|
1215
1282
|
const guid = e[this.GUID_KEY];
|
1216
1283
|
this.entries.delete(guid);
|
1217
1284
|
this.deleteIDEntry(e);
|
1218
|
-
Array.from(this.slices.values()).forEach(s => {
|
1285
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1219
1286
|
s.entries.delete(guid);
|
1220
1287
|
});
|
1221
1288
|
//Create a new array reference to trigger Angular change detection.
|
1222
1289
|
let v = [...Array.from(this.entries.values())];
|
1223
1290
|
const delta = { type: "Delete" /* ActionTypes.DELETE */, entries: [e] };
|
1224
1291
|
this.notifyAll(v, delta);
|
1225
|
-
Array.from(this.slices.values()).forEach(s => {
|
1292
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1226
1293
|
s.delete(e);
|
1227
1294
|
});
|
1228
1295
|
}
|
@@ -1233,29 +1300,29 @@ class EStore extends AbstractStore {
|
|
1233
1300
|
/**
|
1234
1301
|
* Delete N elements.
|
1235
1302
|
* @param ...e
|
1236
|
-
* @example
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1303
|
+
* @example Delete N Todo instance argument.
|
1304
|
+
* ```
|
1305
|
+
* store.deleteN(todo1, todo2);
|
1306
|
+
* ```
|
1240
1307
|
*/
|
1241
1308
|
deleteN(...e) {
|
1242
1309
|
this.deleteA(e);
|
1243
1310
|
}
|
1244
1311
|
/**
|
1245
|
-
* Delete
|
1246
|
-
* @param
|
1247
|
-
* @example
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1312
|
+
* Delete an array of elements.
|
1313
|
+
* @param e The array of instances to be deleted
|
1314
|
+
* @example Delete the array of Todo instances.
|
1315
|
+
* ```
|
1316
|
+
* store.deleteA([todo1, todo2]);
|
1317
|
+
* ```
|
1251
1318
|
*/
|
1252
1319
|
deleteA(e) {
|
1253
|
-
e.forEach(e => {
|
1320
|
+
e.forEach((e) => {
|
1254
1321
|
this.deleteActive(e);
|
1255
1322
|
const guid = e[this.GUID_KEY];
|
1256
1323
|
this.entries.delete(guid);
|
1257
1324
|
this.deleteIDEntry(e);
|
1258
|
-
Array.from(this.slices.values()).forEach(s => {
|
1325
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1259
1326
|
s.entries.delete(guid);
|
1260
1327
|
});
|
1261
1328
|
});
|
@@ -1263,21 +1330,21 @@ class EStore extends AbstractStore {
|
|
1263
1330
|
let v = [...Array.from(this.entries.values())];
|
1264
1331
|
const delta = { type: "Delete" /* ActionTypes.DELETE */, entries: e };
|
1265
1332
|
this.notifyAll(v, delta);
|
1266
|
-
Array.from(this.slices.values()).forEach(s => {
|
1333
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1267
1334
|
s.deleteA(e);
|
1268
1335
|
});
|
1269
1336
|
}
|
1270
1337
|
/**
|
1271
1338
|
* Delete elements by {@link Predicate}.
|
1272
1339
|
* @param p The predicate.
|
1273
|
-
* @example
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1340
|
+
* @example Delete the Todo instances.
|
1341
|
+
* ```
|
1342
|
+
* store.delete(todo1, todo2);
|
1343
|
+
* ```
|
1277
1344
|
*/
|
1278
1345
|
deleteP(p) {
|
1279
1346
|
const d = [];
|
1280
|
-
Array.from(this.entries.values()).forEach(e => {
|
1347
|
+
Array.from(this.entries.values()).forEach((e) => {
|
1281
1348
|
if (p(e)) {
|
1282
1349
|
d.push(e);
|
1283
1350
|
const id = e[this.GUID_KEY];
|
@@ -1290,7 +1357,7 @@ class EStore extends AbstractStore {
|
|
1290
1357
|
let v = [...Array.from(this.entries.values())];
|
1291
1358
|
const delta = { type: "Delete" /* ActionTypes.DELETE */, entries: d };
|
1292
1359
|
this.notifyAll(v, delta);
|
1293
|
-
Array.from(this.slices.values()).forEach(s => {
|
1360
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1294
1361
|
s.deleteA(d);
|
1295
1362
|
});
|
1296
1363
|
}
|
@@ -1323,18 +1390,18 @@ class EStore extends AbstractStore {
|
|
1323
1390
|
* send their own delta notification.
|
1324
1391
|
*
|
1325
1392
|
* @example Reset the store.
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1393
|
+
* ```
|
1394
|
+
* store.reset();
|
1395
|
+
* ```
|
1329
1396
|
*/
|
1330
1397
|
reset() {
|
1331
1398
|
const delta = {
|
1332
1399
|
type: "Reset" /* ActionTypes.RESET */,
|
1333
|
-
entries: Array.from(this.entries.values())
|
1400
|
+
entries: Array.from(this.entries.values()),
|
1334
1401
|
};
|
1335
1402
|
this.notifyAll([], delta);
|
1336
1403
|
this.entries = new Map();
|
1337
|
-
Array.from(this.slices.values()).forEach(s => {
|
1404
|
+
Array.from(this.slices.values()).forEach((s) => {
|
1338
1405
|
s.reset();
|
1339
1406
|
});
|
1340
1407
|
}
|