@ngrx/entity 6.0.1 → 7.0.0-beta.0
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/bundles/entity.umd.js +419 -369
- package/bundles/entity.umd.js.map +1 -1
- package/bundles/entity.umd.min.js +2 -2
- package/bundles/entity.umd.min.js.map +1 -1
- package/entity.metadata.json +1 -1
- package/esm2015/index.js +3 -3
- package/esm2015/public_api.js +3 -3
- package/esm2015/src/create_adapter.js +8 -5
- package/esm2015/src/entity_state.js +2 -2
- package/esm2015/src/index.js +3 -2
- package/esm2015/src/models.js +113 -54
- package/esm2015/src/sorted_state_adapter.js +64 -23
- package/esm2015/src/state_adapter.js +10 -8
- package/esm2015/src/state_selectors.js +10 -6
- package/esm2015/src/unsorted_state_adapter.js +65 -23
- package/esm2015/src/utils.js +21 -0
- package/esm5/index.js +1 -1
- package/esm5/src/create_adapter.js +11 -8
- package/esm5/src/entity_state.js +1 -1
- package/esm5/src/index.js +2 -1
- package/esm5/src/models.js +1 -1
- package/esm5/src/sorted_state_adapter.js +18 -6
- package/esm5/src/state_adapter.js +11 -8
- package/esm5/src/state_selectors.js +1 -1
- package/esm5/src/unsorted_state_adapter.js +26 -7
- package/esm5/src/utils.js +10 -0
- package/fesm2015/entity.js +181 -69
- package/fesm2015/entity.js.map +1 -1
- package/fesm5/entity.js +86 -36
- package/fesm5/entity.js.map +1 -1
- package/migrations/6_0_0/index.js +3 -3
- package/package.json +4 -4
- package/schematics-core/index.d.ts +6 -6
- package/schematics-core/index.js +5 -3
- package/schematics-core/utility/ast-utils.js +13 -11
- package/schematics-core/utility/change.js +1 -1
- package/schematics-core/utility/config.js +1 -1
- package/schematics-core/utility/find-module.js +2 -2
- package/schematics-core/utility/ngrx-utils.d.ts +1 -1
- package/schematics-core/utility/ngrx-utils.js +12 -12
- package/schematics-core/utility/package.js +1 -1
- package/schematics-core/utility/parse-name.js +1 -1
- package/schematics-core/utility/project.d.ts +12 -0
- package/schematics-core/utility/project.js +12 -3
- package/schematics-core/utility/route-utils.js +1 -1
- package/schematics-core/utility/strings.js +1 -1
- package/schematics-core/utility/update.js +1 -1
- package/src/index.d.ts +1 -1
- package/src/models.d.ts +16 -20
- package/src/state_adapter.d.ts +1 -1
- package/src/utils.d.ts +2 -0
package/bundles/entity.umd.js
CHANGED
|
@@ -1,440 +1,490 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license NgRx
|
|
2
|
+
* @license NgRx 7.0.0-beta.0
|
|
3
3
|
* (c) 2015-2018 Brandon Roberts, Mike Ryan, Rob Wormald, Victor Savkin
|
|
4
4
|
* License: MIT
|
|
5
5
|
*/
|
|
6
6
|
(function (global, factory) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}(this, (function (exports,store) { 'use strict';
|
|
7
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngrx/store'), require('@angular/core')) :
|
|
8
|
+
typeof define === 'function' && define.amd ? define('@ngrx/entity', ['exports', '@ngrx/store', '@angular/core'], factory) :
|
|
9
|
+
(factory((global.ngrx = global.ngrx || {}, global.ngrx.entity = {}),global['@ngrx/store'],global.ng.core));
|
|
10
|
+
}(this, (function (exports,store,core) { 'use strict';
|
|
11
11
|
|
|
12
|
-
function getInitialEntityState() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
function createInitialStateFactory() {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
function getInitialEntityState() {
|
|
13
|
+
return {
|
|
14
|
+
ids: [],
|
|
15
|
+
entities: {},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function createInitialStateFactory() {
|
|
19
|
+
function getInitialState(additionalState) {
|
|
20
|
+
if (additionalState === void 0) { additionalState = {}; }
|
|
21
|
+
return Object.assign(getInitialEntityState(), additionalState);
|
|
22
|
+
}
|
|
23
|
+
return { getInitialState: getInitialState };
|
|
22
24
|
}
|
|
23
|
-
return { getInitialState: getInitialState };
|
|
24
|
-
}
|
|
25
25
|
|
|
26
|
-
function createSelectorsFactory() {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
26
|
+
function createSelectorsFactory() {
|
|
27
|
+
function getSelectors(selectState) {
|
|
28
|
+
var selectIds = function (state) { return state.ids; };
|
|
29
|
+
var selectEntities = function (state) { return state.entities; };
|
|
30
|
+
var selectAll = store.createSelector(selectIds, selectEntities, function (ids, entities) {
|
|
31
|
+
return ids.map(function (id) { return entities[id]; });
|
|
32
|
+
});
|
|
33
|
+
var selectTotal = store.createSelector(selectIds, function (ids) { return ids.length; });
|
|
34
|
+
if (!selectState) {
|
|
35
|
+
return {
|
|
36
|
+
selectIds: selectIds,
|
|
37
|
+
selectEntities: selectEntities,
|
|
38
|
+
selectAll: selectAll,
|
|
39
|
+
selectTotal: selectTotal,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
35
42
|
return {
|
|
36
|
-
selectIds: selectIds,
|
|
37
|
-
selectEntities: selectEntities,
|
|
38
|
-
selectAll: selectAll,
|
|
39
|
-
selectTotal: selectTotal,
|
|
43
|
+
selectIds: store.createSelector(selectState, selectIds),
|
|
44
|
+
selectEntities: store.createSelector(selectState, selectEntities),
|
|
45
|
+
selectAll: store.createSelector(selectState, selectAll),
|
|
46
|
+
selectTotal: store.createSelector(selectState, selectTotal),
|
|
40
47
|
};
|
|
41
48
|
}
|
|
42
|
-
return {
|
|
43
|
-
selectIds: store.createSelector(selectState, selectIds),
|
|
44
|
-
selectEntities: store.createSelector(selectState, selectEntities),
|
|
45
|
-
selectAll: store.createSelector(selectState, selectAll),
|
|
46
|
-
selectTotal: store.createSelector(selectState, selectTotal),
|
|
47
|
-
};
|
|
49
|
+
return { getSelectors: getSelectors };
|
|
48
50
|
}
|
|
49
|
-
return { getSelectors: getSelectors };
|
|
50
|
-
}
|
|
51
51
|
|
|
52
|
-
var __assign
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var __read = (undefined && undefined.__read) || function (o, n) {
|
|
61
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
62
|
-
if (!m) return o;
|
|
63
|
-
var i = m.call(o), r, ar = [], e;
|
|
64
|
-
try {
|
|
65
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
66
|
-
}
|
|
67
|
-
catch (error) { e = { error: error }; }
|
|
68
|
-
finally {
|
|
69
|
-
try {
|
|
70
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
71
|
-
}
|
|
72
|
-
finally { if (e) throw e.error; }
|
|
73
|
-
}
|
|
74
|
-
return ar;
|
|
75
|
-
};
|
|
76
|
-
var __spread = (undefined && undefined.__spread) || function () {
|
|
77
|
-
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
78
|
-
return ar;
|
|
79
|
-
};
|
|
80
|
-
var DidMutate;
|
|
81
|
-
(function (DidMutate) {
|
|
82
|
-
DidMutate[DidMutate["EntitiesOnly"] = 0] = "EntitiesOnly";
|
|
83
|
-
DidMutate[DidMutate["Both"] = 1] = "Both";
|
|
84
|
-
DidMutate[DidMutate["None"] = 2] = "None";
|
|
85
|
-
})(DidMutate || (DidMutate = {}));
|
|
86
|
-
function createStateOperator(mutator) {
|
|
87
|
-
return function operation(arg, state) {
|
|
88
|
-
var clonedEntityState = {
|
|
89
|
-
ids: __spread(state.ids),
|
|
90
|
-
entities: __assign$1({}, state.entities),
|
|
52
|
+
var __assign = (undefined && undefined.__assign) || function () {
|
|
53
|
+
__assign = Object.assign || function(t) {
|
|
54
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
55
|
+
s = arguments[i];
|
|
56
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
57
|
+
t[p] = s[p];
|
|
58
|
+
}
|
|
59
|
+
return t;
|
|
91
60
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
61
|
+
return __assign.apply(this, arguments);
|
|
62
|
+
};
|
|
63
|
+
var __read = (undefined && undefined.__read) || function (o, n) {
|
|
64
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
65
|
+
if (!m) return o;
|
|
66
|
+
var i = m.call(o), r, ar = [], e;
|
|
67
|
+
try {
|
|
68
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
95
69
|
}
|
|
96
|
-
|
|
97
|
-
|
|
70
|
+
catch (error) { e = { error: error }; }
|
|
71
|
+
finally {
|
|
72
|
+
try {
|
|
73
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
74
|
+
}
|
|
75
|
+
finally { if (e) throw e.error; }
|
|
98
76
|
}
|
|
99
|
-
return
|
|
77
|
+
return ar;
|
|
100
78
|
};
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
105
|
-
if (m) return m.call(o);
|
|
106
|
-
return {
|
|
107
|
-
next: function () {
|
|
108
|
-
if (o && i >= o.length) o = void 0;
|
|
109
|
-
return { value: o && o[i++], done: !o };
|
|
110
|
-
}
|
|
79
|
+
var __spread = (undefined && undefined.__spread) || function () {
|
|
80
|
+
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
|
81
|
+
return ar;
|
|
111
82
|
};
|
|
112
|
-
|
|
113
|
-
function
|
|
114
|
-
|
|
83
|
+
var DidMutate;
|
|
84
|
+
(function (DidMutate) {
|
|
85
|
+
DidMutate[DidMutate["EntitiesOnly"] = 0] = "EntitiesOnly";
|
|
86
|
+
DidMutate[DidMutate["Both"] = 1] = "Both";
|
|
87
|
+
DidMutate[DidMutate["None"] = 2] = "None";
|
|
88
|
+
})(DidMutate || (DidMutate = {}));
|
|
89
|
+
function createStateOperator(mutator) {
|
|
90
|
+
return function operation(arg, state) {
|
|
91
|
+
var clonedEntityState = {
|
|
92
|
+
ids: __spread(state.ids),
|
|
93
|
+
entities: __assign({}, state.entities),
|
|
94
|
+
};
|
|
95
|
+
var didMutate = mutator(arg, clonedEntityState);
|
|
96
|
+
if (didMutate === DidMutate.Both) {
|
|
97
|
+
return Object.assign({}, state, clonedEntityState);
|
|
98
|
+
}
|
|
99
|
+
if (didMutate === DidMutate.EntitiesOnly) {
|
|
100
|
+
return __assign({}, state, { entities: clonedEntityState.entities });
|
|
101
|
+
}
|
|
102
|
+
return state;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function selectIdValue(entity, selectId) {
|
|
115
107
|
var key = selectId(entity);
|
|
116
|
-
if (key
|
|
117
|
-
|
|
108
|
+
if (core.isDevMode() && key === undefined) {
|
|
109
|
+
console.warn('@ngrx/entity: The entity passed to the `selectId` implementation returned undefined.', 'You should probably provide your own `selectId` implementation.', 'The entity that was passed:', entity, 'The `selectId` implementation:', selectId.toString());
|
|
118
110
|
}
|
|
119
|
-
|
|
120
|
-
state.entities[key] = entity;
|
|
121
|
-
return DidMutate.Both;
|
|
111
|
+
return key;
|
|
122
112
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
113
|
+
|
|
114
|
+
var __values = (undefined && undefined.__values) || function (o) {
|
|
115
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
116
|
+
if (m) return m.call(o);
|
|
117
|
+
return {
|
|
118
|
+
next: function () {
|
|
119
|
+
if (o && i >= o.length) o = void 0;
|
|
120
|
+
return { value: o && o[i++], done: !o };
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
function createUnsortedStateAdapter(selectId) {
|
|
125
|
+
function addOneMutably(entity, state) {
|
|
126
|
+
var key = selectIdValue(entity, selectId);
|
|
127
|
+
if (key in state.entities) {
|
|
128
|
+
return DidMutate.None;
|
|
129
129
|
}
|
|
130
|
+
state.ids.push(key);
|
|
131
|
+
state.entities[key] = entity;
|
|
132
|
+
return DidMutate.Both;
|
|
130
133
|
}
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
function addManyMutably(entities, state) {
|
|
135
|
+
var e_1, _a;
|
|
136
|
+
var didMutate = false;
|
|
133
137
|
try {
|
|
134
|
-
|
|
138
|
+
for (var entities_1 = __values(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
139
|
+
var entity = entities_1_1.value;
|
|
140
|
+
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
144
|
+
finally {
|
|
145
|
+
try {
|
|
146
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
147
|
+
}
|
|
148
|
+
finally { if (e_1) throw e_1.error; }
|
|
135
149
|
}
|
|
136
|
-
|
|
150
|
+
return didMutate ? DidMutate.Both : DidMutate.None;
|
|
137
151
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
state.entities = {};
|
|
144
|
-
addManyMutably(entities, state);
|
|
145
|
-
return DidMutate.Both;
|
|
146
|
-
}
|
|
147
|
-
function removeOneMutably(key, state) {
|
|
148
|
-
return removeManyMutably([key], state);
|
|
149
|
-
}
|
|
150
|
-
function removeManyMutably(keys, state) {
|
|
151
|
-
var didMutate = keys
|
|
152
|
-
.filter(function (key) { return key in state.entities; })
|
|
153
|
-
.map(function (key) { return delete state.entities[key]; }).length > 0;
|
|
154
|
-
if (didMutate) {
|
|
155
|
-
state.ids = state.ids.filter(function (id) { return id in state.entities; });
|
|
152
|
+
function addAllMutably(entities, state) {
|
|
153
|
+
state.ids = [];
|
|
154
|
+
state.entities = {};
|
|
155
|
+
addManyMutably(entities, state);
|
|
156
|
+
return DidMutate.Both;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
function removeAll(state) {
|
|
160
|
-
return Object.assign({}, state, {
|
|
161
|
-
ids: [],
|
|
162
|
-
entities: {},
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
function takeNewKey(keys, update, state) {
|
|
166
|
-
var original = state.entities[update.id];
|
|
167
|
-
var updated = Object.assign({}, original, update.changes);
|
|
168
|
-
var newKey = selectId(updated);
|
|
169
|
-
var hasNewKey = newKey !== update.id;
|
|
170
|
-
if (hasNewKey) {
|
|
171
|
-
keys[update.id] = newKey;
|
|
172
|
-
delete state.entities[update.id];
|
|
158
|
+
function removeOneMutably(key, state) {
|
|
159
|
+
return removeManyMutably([key], state);
|
|
173
160
|
}
|
|
174
|
-
state
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
var didMutateEntities = updates.length > 0;
|
|
184
|
-
if (didMutateEntities) {
|
|
185
|
-
var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
|
|
186
|
-
if (didMutateIds) {
|
|
187
|
-
state.ids = state.ids.map(function (id) { return newKeys[id] || id; });
|
|
188
|
-
return DidMutate.Both;
|
|
161
|
+
function removeManyMutably(keysOrPredicate, state) {
|
|
162
|
+
var keys = keysOrPredicate instanceof Array
|
|
163
|
+
? keysOrPredicate
|
|
164
|
+
: state.ids.filter(function (key) { return keysOrPredicate(state.entities[key]); });
|
|
165
|
+
var didMutate = keys
|
|
166
|
+
.filter(function (key) { return key in state.entities; })
|
|
167
|
+
.map(function (key) { return delete state.entities[key]; }).length > 0;
|
|
168
|
+
if (didMutate) {
|
|
169
|
+
state.ids = state.ids.filter(function (id) { return id in state.entities; });
|
|
189
170
|
}
|
|
190
|
-
|
|
191
|
-
|
|
171
|
+
return didMutate ? DidMutate.Both : DidMutate.None;
|
|
172
|
+
}
|
|
173
|
+
function removeAll(state) {
|
|
174
|
+
return Object.assign({}, state, {
|
|
175
|
+
ids: [],
|
|
176
|
+
entities: {},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
function takeNewKey(keys, update, state) {
|
|
180
|
+
var original = state.entities[update.id];
|
|
181
|
+
var updated = Object.assign({}, original, update.changes);
|
|
182
|
+
var newKey = selectIdValue(updated, selectId);
|
|
183
|
+
var hasNewKey = newKey !== update.id;
|
|
184
|
+
if (hasNewKey) {
|
|
185
|
+
keys[update.id] = newKey;
|
|
186
|
+
delete state.entities[update.id];
|
|
192
187
|
}
|
|
188
|
+
state.entities[newKey] = updated;
|
|
189
|
+
return hasNewKey;
|
|
193
190
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (id in state.entities) {
|
|
207
|
-
updated.push({ id: id, changes: entity });
|
|
191
|
+
function updateOneMutably(update, state) {
|
|
192
|
+
return updateManyMutably([update], state);
|
|
193
|
+
}
|
|
194
|
+
function updateManyMutably(updates, state) {
|
|
195
|
+
var newKeys = {};
|
|
196
|
+
updates = updates.filter(function (update) { return update.id in state.entities; });
|
|
197
|
+
var didMutateEntities = updates.length > 0;
|
|
198
|
+
if (didMutateEntities) {
|
|
199
|
+
var didMutateIds = updates.filter(function (update) { return takeNewKey(newKeys, update, state); }).length > 0;
|
|
200
|
+
if (didMutateIds) {
|
|
201
|
+
state.ids = state.ids.map(function (id) { return newKeys[id] || id; });
|
|
202
|
+
return DidMutate.Both;
|
|
208
203
|
}
|
|
209
204
|
else {
|
|
210
|
-
|
|
205
|
+
return DidMutate.EntitiesOnly;
|
|
211
206
|
}
|
|
212
207
|
}
|
|
208
|
+
return DidMutate.None;
|
|
213
209
|
}
|
|
214
|
-
|
|
215
|
-
|
|
210
|
+
function mapMutably(map, state) {
|
|
211
|
+
var changes = state.ids.reduce(function (changes, id) {
|
|
212
|
+
var change = map(state.entities[id]);
|
|
213
|
+
if (change !== state.entities[id]) {
|
|
214
|
+
changes.push({ id: id, changes: change });
|
|
215
|
+
}
|
|
216
|
+
return changes;
|
|
217
|
+
}, []);
|
|
218
|
+
var updates = changes.filter(function (_a) {
|
|
219
|
+
var id = _a.id;
|
|
220
|
+
return id in state.entities;
|
|
221
|
+
});
|
|
222
|
+
return updateManyMutably(updates, state);
|
|
223
|
+
}
|
|
224
|
+
function upsertOneMutably(entity, state) {
|
|
225
|
+
return upsertManyMutably([entity], state);
|
|
226
|
+
}
|
|
227
|
+
function upsertManyMutably(entities, state) {
|
|
228
|
+
var e_2, _a;
|
|
229
|
+
var added = [];
|
|
230
|
+
var updated = [];
|
|
216
231
|
try {
|
|
217
|
-
|
|
232
|
+
for (var entities_2 = __values(entities), entities_2_1 = entities_2.next(); !entities_2_1.done; entities_2_1 = entities_2.next()) {
|
|
233
|
+
var entity = entities_2_1.value;
|
|
234
|
+
var id = selectIdValue(entity, selectId);
|
|
235
|
+
if (id in state.entities) {
|
|
236
|
+
updated.push({ id: id, changes: entity });
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
added.push(entity);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
244
|
+
finally {
|
|
245
|
+
try {
|
|
246
|
+
if (entities_2_1 && !entities_2_1.done && (_a = entities_2.return)) _a.call(entities_2);
|
|
247
|
+
}
|
|
248
|
+
finally { if (e_2) throw e_2.error; }
|
|
249
|
+
}
|
|
250
|
+
var didMutateByUpdated = updateManyMutably(updated, state);
|
|
251
|
+
var didMutateByAdded = addManyMutably(added, state);
|
|
252
|
+
switch (true) {
|
|
253
|
+
case didMutateByAdded === DidMutate.None &&
|
|
254
|
+
didMutateByUpdated === DidMutate.None:
|
|
255
|
+
return DidMutate.None;
|
|
256
|
+
case didMutateByAdded === DidMutate.Both ||
|
|
257
|
+
didMutateByUpdated === DidMutate.Both:
|
|
258
|
+
return DidMutate.Both;
|
|
259
|
+
default:
|
|
260
|
+
return DidMutate.EntitiesOnly;
|
|
218
261
|
}
|
|
219
|
-
finally { if (e_2) throw e_2.error; }
|
|
220
|
-
}
|
|
221
|
-
var didMutateByUpdated = updateManyMutably(updated, state);
|
|
222
|
-
var didMutateByAdded = addManyMutably(added, state);
|
|
223
|
-
switch (true) {
|
|
224
|
-
case didMutateByAdded === DidMutate.None &&
|
|
225
|
-
didMutateByUpdated === DidMutate.None:
|
|
226
|
-
return DidMutate.None;
|
|
227
|
-
case didMutateByAdded === DidMutate.Both ||
|
|
228
|
-
didMutateByUpdated === DidMutate.Both:
|
|
229
|
-
return DidMutate.Both;
|
|
230
|
-
default:
|
|
231
|
-
return DidMutate.EntitiesOnly;
|
|
232
262
|
}
|
|
233
|
-
|
|
263
|
+
return {
|
|
264
|
+
removeAll: removeAll,
|
|
265
|
+
addOne: createStateOperator(addOneMutably),
|
|
266
|
+
addMany: createStateOperator(addManyMutably),
|
|
267
|
+
addAll: createStateOperator(addAllMutably),
|
|
268
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
269
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
270
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
271
|
+
upsertMany: createStateOperator(upsertManyMutably),
|
|
272
|
+
removeOne: createStateOperator(removeOneMutably),
|
|
273
|
+
removeMany: createStateOperator(removeManyMutably),
|
|
274
|
+
map: createStateOperator(mapMutably),
|
|
275
|
+
};
|
|
234
276
|
}
|
|
235
|
-
return {
|
|
236
|
-
removeAll: removeAll,
|
|
237
|
-
addOne: createStateOperator(addOneMutably),
|
|
238
|
-
addMany: createStateOperator(addManyMutably),
|
|
239
|
-
addAll: createStateOperator(addAllMutably),
|
|
240
|
-
updateOne: createStateOperator(updateOneMutably),
|
|
241
|
-
updateMany: createStateOperator(updateManyMutably),
|
|
242
|
-
upsertOne: createStateOperator(upsertOneMutably),
|
|
243
|
-
upsertMany: createStateOperator(upsertManyMutably),
|
|
244
|
-
removeOne: createStateOperator(removeOneMutably),
|
|
245
|
-
removeMany: createStateOperator(removeManyMutably),
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
277
|
|
|
249
|
-
var __values = (undefined && undefined.__values) || function (o) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
278
|
+
var __values$1 = (undefined && undefined.__values) || function (o) {
|
|
279
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
|
280
|
+
if (m) return m.call(o);
|
|
281
|
+
return {
|
|
282
|
+
next: function () {
|
|
283
|
+
if (o && i >= o.length) o = void 0;
|
|
284
|
+
return { value: o && o[i++], done: !o };
|
|
285
|
+
}
|
|
286
|
+
};
|
|
257
287
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
return addManyMutably([entity], state);
|
|
263
|
-
}
|
|
264
|
-
function addManyMutably(newModels, state) {
|
|
265
|
-
var models = newModels.filter(function (model) { return !(selectId(model) in state.entities); });
|
|
266
|
-
if (models.length === 0) {
|
|
267
|
-
return DidMutate.None;
|
|
288
|
+
function createSortedStateAdapter(selectId, sort) {
|
|
289
|
+
var _a = createUnsortedStateAdapter(selectId), removeOne = _a.removeOne, removeMany = _a.removeMany, removeAll = _a.removeAll;
|
|
290
|
+
function addOneMutably(entity, state) {
|
|
291
|
+
return addManyMutably([entity], state);
|
|
268
292
|
}
|
|
269
|
-
|
|
270
|
-
|
|
293
|
+
function addManyMutably(newModels, state) {
|
|
294
|
+
var models = newModels.filter(function (model) { return !(selectIdValue(model, selectId) in state.entities); });
|
|
295
|
+
if (models.length === 0) {
|
|
296
|
+
return DidMutate.None;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
merge(models, state);
|
|
300
|
+
return DidMutate.Both;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
function addAllMutably(models, state) {
|
|
304
|
+
state.entities = {};
|
|
305
|
+
state.ids = [];
|
|
306
|
+
addManyMutably(models, state);
|
|
271
307
|
return DidMutate.Both;
|
|
272
308
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
state.entities = {};
|
|
276
|
-
state.ids = [];
|
|
277
|
-
addManyMutably(models, state);
|
|
278
|
-
return DidMutate.Both;
|
|
279
|
-
}
|
|
280
|
-
function updateOneMutably(update, state) {
|
|
281
|
-
return updateManyMutably([update], state);
|
|
282
|
-
}
|
|
283
|
-
function takeUpdatedModel(models, update, state) {
|
|
284
|
-
if (!(update.id in state.entities)) {
|
|
285
|
-
return false;
|
|
309
|
+
function updateOneMutably(update, state) {
|
|
310
|
+
return updateManyMutably([update], state);
|
|
286
311
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
0;
|
|
298
|
-
if (models.length === 0) {
|
|
299
|
-
return DidMutate.None;
|
|
312
|
+
function takeUpdatedModel(models, update, state) {
|
|
313
|
+
if (!(update.id in state.entities)) {
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
var original = state.entities[update.id];
|
|
317
|
+
var updated = Object.assign({}, original, update.changes);
|
|
318
|
+
var newKey = selectIdValue(updated, selectId);
|
|
319
|
+
delete state.entities[update.id];
|
|
320
|
+
models.push(updated);
|
|
321
|
+
return newKey !== update.id;
|
|
300
322
|
}
|
|
301
|
-
|
|
302
|
-
var
|
|
303
|
-
var
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
else {
|
|
309
|
-
updatedIndexes_1.push(index);
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
});
|
|
313
|
-
merge(models, state);
|
|
314
|
-
if (!didMutateIds &&
|
|
315
|
-
updatedIndexes_1.every(function (i) { return state.ids[i] === originalIds_1[i]; })) {
|
|
316
|
-
return DidMutate.EntitiesOnly;
|
|
323
|
+
function updateManyMutably(updates, state) {
|
|
324
|
+
var models = [];
|
|
325
|
+
var didMutateIds = updates.filter(function (update) { return takeUpdatedModel(models, update, state); }).length >
|
|
326
|
+
0;
|
|
327
|
+
if (models.length === 0) {
|
|
328
|
+
return DidMutate.None;
|
|
317
329
|
}
|
|
318
330
|
else {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
updated.push({ id: id, changes: entity });
|
|
331
|
+
var originalIds_1 = state.ids;
|
|
332
|
+
var updatedIndexes_1 = [];
|
|
333
|
+
state.ids = state.ids.filter(function (id, index) {
|
|
334
|
+
if (id in state.entities) {
|
|
335
|
+
return true;
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
updatedIndexes_1.push(index);
|
|
339
|
+
return false;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
merge(models, state);
|
|
343
|
+
if (!didMutateIds &&
|
|
344
|
+
updatedIndexes_1.every(function (i) { return state.ids[i] === originalIds_1[i]; })) {
|
|
345
|
+
return DidMutate.EntitiesOnly;
|
|
335
346
|
}
|
|
336
347
|
else {
|
|
337
|
-
|
|
348
|
+
return DidMutate.Both;
|
|
338
349
|
}
|
|
339
350
|
}
|
|
340
351
|
}
|
|
341
|
-
|
|
342
|
-
|
|
352
|
+
function mapMutably(updatesOrMap, state) {
|
|
353
|
+
var updates = state.ids.reduce(function (changes, id) {
|
|
354
|
+
var change = updatesOrMap(state.entities[id]);
|
|
355
|
+
if (change !== state.entities[id]) {
|
|
356
|
+
changes.push({ id: id, changes: change });
|
|
357
|
+
}
|
|
358
|
+
return changes;
|
|
359
|
+
}, []);
|
|
360
|
+
return updateManyMutably(updates, state);
|
|
361
|
+
}
|
|
362
|
+
function upsertOneMutably(entity, state) {
|
|
363
|
+
return upsertManyMutably([entity], state);
|
|
364
|
+
}
|
|
365
|
+
function upsertManyMutably(entities, state) {
|
|
366
|
+
var e_1, _a;
|
|
367
|
+
var added = [];
|
|
368
|
+
var updated = [];
|
|
343
369
|
try {
|
|
344
|
-
|
|
370
|
+
for (var entities_1 = __values$1(entities), entities_1_1 = entities_1.next(); !entities_1_1.done; entities_1_1 = entities_1.next()) {
|
|
371
|
+
var entity = entities_1_1.value;
|
|
372
|
+
var id = selectIdValue(entity, selectId);
|
|
373
|
+
if (id in state.entities) {
|
|
374
|
+
updated.push({ id: id, changes: entity });
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
added.push(entity);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
382
|
+
finally {
|
|
383
|
+
try {
|
|
384
|
+
if (entities_1_1 && !entities_1_1.done && (_a = entities_1.return)) _a.call(entities_1);
|
|
385
|
+
}
|
|
386
|
+
finally { if (e_1) throw e_1.error; }
|
|
387
|
+
}
|
|
388
|
+
var didMutateByUpdated = updateManyMutably(updated, state);
|
|
389
|
+
var didMutateByAdded = addManyMutably(added, state);
|
|
390
|
+
switch (true) {
|
|
391
|
+
case didMutateByAdded === DidMutate.None &&
|
|
392
|
+
didMutateByUpdated === DidMutate.None:
|
|
393
|
+
return DidMutate.None;
|
|
394
|
+
case didMutateByAdded === DidMutate.Both ||
|
|
395
|
+
didMutateByUpdated === DidMutate.Both:
|
|
396
|
+
return DidMutate.Both;
|
|
397
|
+
default:
|
|
398
|
+
return DidMutate.EntitiesOnly;
|
|
345
399
|
}
|
|
346
|
-
finally { if (e_1) throw e_1.error; }
|
|
347
|
-
}
|
|
348
|
-
var didMutateByUpdated = updateManyMutably(updated, state);
|
|
349
|
-
var didMutateByAdded = addManyMutably(added, state);
|
|
350
|
-
switch (true) {
|
|
351
|
-
case didMutateByAdded === DidMutate.None &&
|
|
352
|
-
didMutateByUpdated === DidMutate.None:
|
|
353
|
-
return DidMutate.None;
|
|
354
|
-
case didMutateByAdded === DidMutate.Both ||
|
|
355
|
-
didMutateByUpdated === DidMutate.Both:
|
|
356
|
-
return DidMutate.Both;
|
|
357
|
-
default:
|
|
358
|
-
return DidMutate.EntitiesOnly;
|
|
359
400
|
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
401
|
+
function merge(models, state) {
|
|
402
|
+
models.sort(sort);
|
|
403
|
+
var ids = [];
|
|
404
|
+
var i = 0;
|
|
405
|
+
var j = 0;
|
|
406
|
+
while (i < models.length && j < state.ids.length) {
|
|
407
|
+
var model = models[i];
|
|
408
|
+
var modelId = selectIdValue(model, selectId);
|
|
409
|
+
var entityId = state.ids[j];
|
|
410
|
+
var entity = state.entities[entityId];
|
|
411
|
+
if (sort(model, entity) <= 0) {
|
|
412
|
+
ids.push(modelId);
|
|
413
|
+
i++;
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
ids.push(entityId);
|
|
417
|
+
j++;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
if (i < models.length) {
|
|
421
|
+
state.ids = ids.concat(models.slice(i).map(selectId));
|
|
375
422
|
}
|
|
376
423
|
else {
|
|
377
|
-
ids.
|
|
378
|
-
j++;
|
|
424
|
+
state.ids = ids.concat(state.ids.slice(j));
|
|
379
425
|
}
|
|
426
|
+
models.forEach(function (model, i) {
|
|
427
|
+
state.entities[selectId(model)] = model;
|
|
428
|
+
});
|
|
380
429
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
430
|
+
return {
|
|
431
|
+
removeOne: removeOne,
|
|
432
|
+
removeMany: removeMany,
|
|
433
|
+
removeAll: removeAll,
|
|
434
|
+
addOne: createStateOperator(addOneMutably),
|
|
435
|
+
updateOne: createStateOperator(updateOneMutably),
|
|
436
|
+
upsertOne: createStateOperator(upsertOneMutably),
|
|
437
|
+
addAll: createStateOperator(addAllMutably),
|
|
438
|
+
addMany: createStateOperator(addManyMutably),
|
|
439
|
+
updateMany: createStateOperator(updateManyMutably),
|
|
440
|
+
upsertMany: createStateOperator(upsertManyMutably),
|
|
441
|
+
map: createStateOperator(mapMutably),
|
|
442
|
+
};
|
|
390
443
|
}
|
|
391
|
-
return {
|
|
392
|
-
removeOne: removeOne,
|
|
393
|
-
removeMany: removeMany,
|
|
394
|
-
removeAll: removeAll,
|
|
395
|
-
addOne: createStateOperator(addOneMutably),
|
|
396
|
-
updateOne: createStateOperator(updateOneMutably),
|
|
397
|
-
upsertOne: createStateOperator(upsertOneMutably),
|
|
398
|
-
addAll: createStateOperator(addAllMutably),
|
|
399
|
-
addMany: createStateOperator(addManyMutably),
|
|
400
|
-
updateMany: createStateOperator(updateManyMutably),
|
|
401
|
-
upsertMany: createStateOperator(upsertManyMutably),
|
|
402
|
-
};
|
|
403
|
-
}
|
|
404
444
|
|
|
405
|
-
var __assign = (undefined && undefined.__assign) ||
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
445
|
+
var __assign$1 = (undefined && undefined.__assign) || function () {
|
|
446
|
+
__assign$1 = Object.assign || function(t) {
|
|
447
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
448
|
+
s = arguments[i];
|
|
449
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
450
|
+
t[p] = s[p];
|
|
451
|
+
}
|
|
452
|
+
return t;
|
|
453
|
+
};
|
|
454
|
+
return __assign$1.apply(this, arguments);
|
|
455
|
+
};
|
|
456
|
+
function createEntityAdapter(options) {
|
|
457
|
+
if (options === void 0) { options = {}; }
|
|
458
|
+
var _a = __assign$1({ sortComparer: false, selectId: function (instance) { return instance.id; } }, options), selectId = _a.selectId, sortComparer = _a.sortComparer;
|
|
459
|
+
var stateFactory = createInitialStateFactory();
|
|
460
|
+
var selectorsFactory = createSelectorsFactory();
|
|
461
|
+
var stateAdapter = sortComparer
|
|
462
|
+
? createSortedStateAdapter(selectId, sortComparer)
|
|
463
|
+
: createUnsortedStateAdapter(selectId);
|
|
464
|
+
return __assign$1({ selectId: selectId,
|
|
465
|
+
sortComparer: sortComparer }, stateFactory, selectorsFactory, stateAdapter);
|
|
410
466
|
}
|
|
411
|
-
return t;
|
|
412
|
-
};
|
|
413
|
-
function createEntityAdapter(options) {
|
|
414
|
-
if (options === void 0) { options = {}; }
|
|
415
|
-
var _a = __assign({ sortComparer: false, selectId: function (instance) { return instance.id; } }, options), selectId = _a.selectId, sortComparer = _a.sortComparer;
|
|
416
|
-
var stateFactory = createInitialStateFactory();
|
|
417
|
-
var selectorsFactory = createSelectorsFactory();
|
|
418
|
-
var stateAdapter = sortComparer
|
|
419
|
-
? createSortedStateAdapter(selectId, sortComparer)
|
|
420
|
-
: createUnsortedStateAdapter(selectId);
|
|
421
|
-
return __assign({ selectId: selectId,
|
|
422
|
-
sortComparer: sortComparer }, stateFactory, selectorsFactory, stateAdapter);
|
|
423
|
-
}
|
|
424
467
|
|
|
425
|
-
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
468
|
+
var Dictionary = /** @class */ (function () {
|
|
469
|
+
function Dictionary() {
|
|
470
|
+
}
|
|
471
|
+
return Dictionary;
|
|
472
|
+
}());
|
|
430
473
|
|
|
431
|
-
/**
|
|
432
|
-
|
|
433
|
-
|
|
474
|
+
/**
|
|
475
|
+
* DO NOT EDIT
|
|
476
|
+
*
|
|
477
|
+
* This file is automatically generated at build
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Generated bundle index. Do not edit.
|
|
482
|
+
*/
|
|
434
483
|
|
|
435
|
-
exports.createEntityAdapter = createEntityAdapter;
|
|
484
|
+
exports.createEntityAdapter = createEntityAdapter;
|
|
485
|
+
exports.Dictionary = Dictionary;
|
|
436
486
|
|
|
437
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
487
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
438
488
|
|
|
439
489
|
})));
|
|
440
490
|
//# sourceMappingURL=entity.umd.js.map
|