@ngrx/entity
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -131,5 +131,5 @@ import { createSelector } from '@ngrx/store'; | ||
var /** @type {?} */ didMutate = false; | ||
for (var /** @type {?} */ index in entities) { | ||
didMutate = | ||
addOneMutably(entities[index], state) !== DidMutate.None || didMutate; | ||
for (var _i = 0, entities_1 = entities; _i < entities_1.length; _i++) { | ||
var entity = entities_1[_i]; | ||
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate; | ||
} | ||
@@ -229,2 +229,40 @@ return didMutate ? DidMutate.Both : DidMutate.None; | ||
} | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
var /** @type {?} */ added = []; | ||
var /** @type {?} */ updated = []; | ||
for (var _i = 0, updates_1 = updates; _i < updates_1.length; _i++) { | ||
var update = updates_1[_i]; | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
var /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
var /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
return { | ||
@@ -237,2 +275,4 @@ removeAll: removeAll, | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
removeOne: createStateOperator(removeOneMutably), | ||
@@ -348,2 +388,40 @@ removeMany: createStateOperator(removeManyMutably), | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
var /** @type {?} */ added = []; | ||
var /** @type {?} */ updated = []; | ||
for (var _i = 0, updates_2 = updates; _i < updates_2.length; _i++) { | ||
var update = updates_2[_i]; | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
var /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
var /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
/** | ||
* @param {?} models | ||
@@ -388,5 +466,7 @@ * @param {?} state | ||
updateOne: createStateOperator(updateOneMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
addAll: createStateOperator(addAllMutably), | ||
addMany: createStateOperator(addManyMutably), | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
}; | ||
@@ -393,0 +473,0 @@ } |
@@ -134,5 +134,4 @@ import { createSelector } from '@ngrx/store'; | ||
let /** @type {?} */ didMutate = false; | ||
for (let /** @type {?} */ index in entities) { | ||
didMutate = | ||
addOneMutably(entities[index], state) !== DidMutate.None || didMutate; | ||
for (const /** @type {?} */ entity of entities) { | ||
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate; | ||
} | ||
@@ -232,2 +231,39 @@ return didMutate ? DidMutate.Both : DidMutate.None; | ||
} | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
const /** @type {?} */ added = []; | ||
const /** @type {?} */ updated = []; | ||
for (const /** @type {?} */ update of updates) { | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
const /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
const /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
return { | ||
@@ -240,2 +276,4 @@ removeAll, | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
removeOne: createStateOperator(removeOneMutably), | ||
@@ -352,2 +390,39 @@ removeMany: createStateOperator(removeManyMutably), | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
const /** @type {?} */ added = []; | ||
const /** @type {?} */ updated = []; | ||
for (const /** @type {?} */ update of updates) { | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
const /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
const /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
/** | ||
* @param {?} models | ||
@@ -392,5 +467,7 @@ * @param {?} state | ||
updateOne: createStateOperator(updateOneMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
addAll: createStateOperator(addAllMutably), | ||
addMany: createStateOperator(addManyMutably), | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
}; | ||
@@ -397,0 +474,0 @@ } |
@@ -136,5 +136,5 @@ (function (global, factory) { | ||
var /** @type {?} */ didMutate = false; | ||
for (var /** @type {?} */ index in entities) { | ||
didMutate = | ||
addOneMutably(entities[index], state) !== DidMutate.None || didMutate; | ||
for (var _i = 0, entities_1 = entities; _i < entities_1.length; _i++) { | ||
var entity = entities_1[_i]; | ||
didMutate = addOneMutably(entity, state) !== DidMutate.None || didMutate; | ||
} | ||
@@ -234,2 +234,40 @@ return didMutate ? DidMutate.Both : DidMutate.None; | ||
} | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
var /** @type {?} */ added = []; | ||
var /** @type {?} */ updated = []; | ||
for (var _i = 0, updates_1 = updates; _i < updates_1.length; _i++) { | ||
var update = updates_1[_i]; | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
var /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
var /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
return { | ||
@@ -242,2 +280,4 @@ removeAll: removeAll, | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
removeOne: createStateOperator(removeOneMutably), | ||
@@ -353,2 +393,40 @@ removeMany: createStateOperator(removeManyMutably), | ||
/** | ||
* @param {?} update | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertOneMutably(update, state) { | ||
return upsertManyMutably([update], state); | ||
} | ||
/** | ||
* @param {?} updates | ||
* @param {?} state | ||
* @return {?} | ||
*/ | ||
function upsertManyMutably(updates, state) { | ||
var /** @type {?} */ added = []; | ||
var /** @type {?} */ updated = []; | ||
for (var _i = 0, updates_2 = updates; _i < updates_2.length; _i++) { | ||
var update = updates_2[_i]; | ||
if (update.id in state.entities) { | ||
updated.push(update); | ||
} | ||
else { | ||
added.push(Object.assign({}, update.changes, { id: update.id })); | ||
} | ||
} | ||
var /** @type {?} */ didMutateByUpdated = updateManyMutably(updated, state); | ||
var /** @type {?} */ didMutateByAdded = addManyMutably(added, state); | ||
switch (true) { | ||
case didMutateByAdded === DidMutate.None && | ||
didMutateByUpdated === DidMutate.None: | ||
return DidMutate.None; | ||
case didMutateByAdded === DidMutate.Both || | ||
didMutateByUpdated === DidMutate.Both: | ||
return DidMutate.Both; | ||
default: | ||
return DidMutate.EntitiesOnly; | ||
} | ||
} | ||
/** | ||
* @param {?} models | ||
@@ -393,5 +471,7 @@ * @param {?} state | ||
updateOne: createStateOperator(updateOneMutably), | ||
upsertOne: createStateOperator(upsertOneMutably), | ||
addAll: createStateOperator(addAllMutably), | ||
addMany: createStateOperator(addManyMutably), | ||
updateMany: createStateOperator(updateManyMutably), | ||
upsertMany: createStateOperator(upsertManyMutably), | ||
}; | ||
@@ -398,0 +478,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ngrx/store")):"function"==typeof define&&define.amd?define(["exports","@ngrx/store"],t):t((e.ngrx=e.ngrx||{},e.ngrx.entity={}),e.ngrx.store)}(this,function(e,t){"use strict";function n(e){return function(t,n){var i={ids:n.ids.slice(),entities:Object.assign({},n.entities)},r=e(t,i);return r===s.Both?Object.assign({},n,i):r===s.EntitiesOnly?Object.assign({},n,{entities:i.entities}):n}}function i(e){function t(t,n){var i=e(t);return i in n.entities?s.None:(n.ids.push(i),n.entities[i]=t,s.Both)}function i(e,n){var i=!1;for(var r in e)i=t(e[r],n)!==s.None||i;return i?s.Both:s.None}function r(e,t){var n=e.filter(function(e){return e in t.entities}).map(function(e){return delete t.entities[e]}).length>0;return n&&(t.ids=t.ids.filter(function(e){return e in t.entities})),n?s.Both:s.None}function o(t,n){var i={};if((t=t.filter(function(e){return e.id in n.entities})).length>0){return t.filter(function(t){return function(t,n,i){var r=i.entities[n.id],o=Object.assign({},r,n.changes),s=e(o),u=s!==n.id;return u&&(t[n.id]=s,delete i.entities[n.id]),i.entities[s]=o,u}(i,t,n)}).length>0?(n.ids=n.ids.map(function(e){return i[e]||e}),s.Both):s.EntitiesOnly}return s.None}return{removeAll:function(e){return Object.assign({},e,{ids:[],entities:{}})},addOne:n(t),addMany:n(i),addAll:n(function(e,t){return t.ids=[],t.entities={},i(e,t),s.Both}),updateOne:n(function(e,t){return o([e],t)}),updateMany:n(o),removeOne:n(function(e,t){return r([e],t)}),removeMany:n(r)}}function r(e,t){function r(t,n){var i=t.filter(function(t){return!(e(t)in n.entities)});return 0===i.length?s.None:(u(i,n),s.Both)}function o(t,n){var i=[],r=t.filter(function(t){return function(t,n,i){if(!(n.id in i.entities))return!1;var r=i.entities[n.id],o=Object.assign({},r,n.changes),s=e(o);return delete i.entities[n.id],t.push(o),s!==n.id}(i,t,n)}).length>0;if(0===i.length)return s.None;var o=n.ids,c=[];return n.ids=n.ids.filter(function(e,t){return e in n.entities||(c.push(t),!1)}),u(i,n),!r&&c.every(function(e){return n.ids[e]===o[e]})?s.EntitiesOnly:s.Both}function u(n,i){n.sort(t);for(var r=[],o=0,s=0;o<n.length&&s<i.ids.length;){var u=n[o],c=e(u),a=i.ids[s],d=i.entities[a];t(u,d)<=0?(r.push(c),o++):(r.push(a),s++)}o<n.length?i.ids=r.concat(n.slice(o).map(e)):i.ids=r.concat(i.ids.slice(s)),n.forEach(function(t,n){i.entities[e(t)]=t})}var c=i(e);return{removeOne:c.removeOne,removeMany:c.removeMany,removeAll:c.removeAll,addOne:n(function(e,t){return r([e],t)}),updateOne:n(function(e,t){return o([e],t)}),addAll:n(function(e,t){return t.entities={},t.ids=[],r(e,t),s.Both}),addMany:n(r),updateMany:n(o)}}function o(e){void 0===e&&(e={});var n=Object.assign({sortComparer:!1,selectId:function(e){return e.id}},e),o=n.selectId,s=n.sortComparer,u={getInitialState:function(e){return void 0===e&&(e={}),Object.assign({ids:[],entities:{}},e)}},c={getSelectors:function(e){var n=function(e){return e.ids},i=function(e){return e.entities},r=t.createSelector(n,i,function(e,t){return e.map(function(e){return t[e]})}),o=t.createSelector(n,function(e){return e.length});return e?{selectIds:t.createSelector(e,n),selectEntities:t.createSelector(e,i),selectAll:t.createSelector(e,r),selectTotal:t.createSelector(e,o)}:{selectIds:n,selectEntities:i,selectAll:r,selectTotal:o}}},a=s?r(o,s):i(o);return Object.assign({},u,c,a)}var s={EntitiesOnly:0,Both:1,None:2};s[s.EntitiesOnly]="EntitiesOnly",s[s.Both]="Both",s[s.None]="None",e.createEntityAdapter=o,Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@ngrx/store")):"function"==typeof define&&define.amd?define(["exports","@ngrx/store"],t):t((e.ngrx=e.ngrx||{},e.ngrx.entity={}),e.ngrx.store)}(this,function(e,t){"use strict";function n(e){return function(t,n){var i={ids:n.ids.slice(),entities:Object.assign({},n.entities)},r=e(t,i);return r===o.Both?Object.assign({},n,i):r===o.EntitiesOnly?Object.assign({},n,{entities:i.entities}):n}}function i(e){function t(t,n){var i=e(t);return i in n.entities?o.None:(n.ids.push(i),n.entities[i]=t,o.Both)}function i(e,n){for(var i=!1,r=0,s=e;r<s.length;r++){i=t(s[r],n)!==o.None||i}return i?o.Both:o.None}function r(e,t){var n=e.filter(function(e){return e in t.entities}).map(function(e){return delete t.entities[e]}).length>0;return n&&(t.ids=t.ids.filter(function(e){return e in t.entities})),n?o.Both:o.None}function s(t,n){var i={};if((t=t.filter(function(e){return e.id in n.entities})).length>0){return t.filter(function(t){return function(t,n,i){var r=i.entities[n.id],s=Object.assign({},r,n.changes),o=e(s),u=o!==n.id;return u&&(t[n.id]=o,delete i.entities[n.id]),i.entities[o]=s,u}(i,t,n)}).length>0?(n.ids=n.ids.map(function(e){return i[e]||e}),o.Both):o.EntitiesOnly}return o.None}function u(e,t){for(var n=[],r=[],u=0,c=e;u<c.length;u++){var a=c[u];a.id in t.entities?r.push(a):n.push(Object.assign({},a.changes,{id:a.id}))}var d=s(r,t),l=i(n,t);switch(!0){case l===o.None&&d===o.None:return o.None;case l===o.Both||d===o.Both:return o.Both;default:return o.EntitiesOnly}}return{removeAll:function(e){return Object.assign({},e,{ids:[],entities:{}})},addOne:n(t),addMany:n(i),addAll:n(function(e,t){return t.ids=[],t.entities={},i(e,t),o.Both}),updateOne:n(function(e,t){return s([e],t)}),updateMany:n(s),upsertOne:n(function(e,t){return u([e],t)}),upsertMany:n(u),removeOne:n(function(e,t){return r([e],t)}),removeMany:n(r)}}function r(e,t){function r(t,n){var i=t.filter(function(t){return!(e(t)in n.entities)});return 0===i.length?o.None:(c(i,n),o.Both)}function s(t,n){var i=[],r=t.filter(function(t){return function(t,n,i){if(!(n.id in i.entities))return!1;var r=i.entities[n.id],s=Object.assign({},r,n.changes),o=e(s);return delete i.entities[n.id],t.push(s),o!==n.id}(i,t,n)}).length>0;if(0===i.length)return o.None;var s=n.ids,u=[];return n.ids=n.ids.filter(function(e,t){return e in n.entities||(u.push(t),!1)}),c(i,n),!r&&u.every(function(e){return n.ids[e]===s[e]})?o.EntitiesOnly:o.Both}function u(e,t){for(var n=[],i=[],u=0,c=e;u<c.length;u++){var a=c[u];a.id in t.entities?i.push(a):n.push(Object.assign({},a.changes,{id:a.id}))}var d=s(i,t),l=r(n,t);switch(!0){case l===o.None&&d===o.None:return o.None;case l===o.Both||d===o.Both:return o.Both;default:return o.EntitiesOnly}}function c(n,i){n.sort(t);for(var r=[],s=0,o=0;s<n.length&&o<i.ids.length;){var u=n[s],c=e(u),a=i.ids[o],d=i.entities[a];t(u,d)<=0?(r.push(c),s++):(r.push(a),o++)}s<n.length?i.ids=r.concat(n.slice(s).map(e)):i.ids=r.concat(i.ids.slice(o)),n.forEach(function(t,n){i.entities[e(t)]=t})}var a=i(e);return{removeOne:a.removeOne,removeMany:a.removeMany,removeAll:a.removeAll,addOne:n(function(e,t){return r([e],t)}),updateOne:n(function(e,t){return s([e],t)}),upsertOne:n(function(e,t){return u([e],t)}),addAll:n(function(e,t){return t.entities={},t.ids=[],r(e,t),o.Both}),addMany:n(r),updateMany:n(s),upsertMany:n(u)}}function s(e){void 0===e&&(e={});var n=Object.assign({sortComparer:!1,selectId:function(e){return e.id}},e),s=n.selectId,o=n.sortComparer,u={getInitialState:function(e){return void 0===e&&(e={}),Object.assign({ids:[],entities:{}},e)}},c={getSelectors:function(e){var n=function(e){return e.ids},i=function(e){return e.entities},r=t.createSelector(n,i,function(e,t){return e.map(function(e){return t[e]})}),s=t.createSelector(n,function(e){return e.length});return e?{selectIds:t.createSelector(e,n),selectEntities:t.createSelector(e,i),selectAll:t.createSelector(e,r),selectTotal:t.createSelector(e,s)}:{selectIds:n,selectEntities:i,selectAll:r,selectTotal:s}}},a=o?r(s,o):i(s);return Object.assign({},u,c,a)}var o={EntitiesOnly:0,Both:1,None:2};o[o.EntitiesOnly]="EntitiesOnly",o[o.Both]="Both",o[o.None]="None",e.createEntityAdapter=s,Object.defineProperty(e,"__esModule",{value:!0})}); |
{ | ||
"name": "@ngrx/entity", | ||
"version": "5.0.1", | ||
"version": "5.1.0", | ||
"description": "Common utilities for entity reducers", | ||
@@ -5,0 +5,0 @@ "module": "@ngrx/entity.es5.js", |
@@ -49,2 +49,4 @@ export declare type ComparerStr<T> = { | ||
updateMany<S extends EntityState<T>>(updates: Update<T>[], state: S): S; | ||
upsertOne<S extends EntityState<T>>(update: Update<T>, state: S): S; | ||
upsertMany<S extends EntityState<T>>(updates: Update<T>[], state: S): S; | ||
} | ||
@@ -51,0 +53,0 @@ export declare type EntitySelectors<T, V> = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
143850
1599