normalized-reducer
Advanced tools
Comparing version 0.3.2 to 0.4.0
@@ -32,6 +32,7 @@ import { Schema, Namespaced, State } from './interfaces'; | ||
}; | ||
reducer: (state: S | undefined, action: import("./interfaces").AnyAction) => S; | ||
reducer: import("./interfaces").Reducer<S>; | ||
}; | ||
export * from './interfaces'; | ||
export * from './enums'; | ||
export * from './normalizr'; | ||
export default makeNormalizedSlice; |
@@ -90,8 +90,8 @@ import { Cardinalities, UpdateActionMethod } from './enums'; | ||
} | ||
export interface SortAction<T extends Entity = Entity> { | ||
export interface SortAction { | ||
type: string; | ||
entityType: string; | ||
compare: Compare<T>; | ||
compare: Compare; | ||
} | ||
export interface SortAttachedAction<T extends Entity = Entity> { | ||
export interface SortAttachedAction { | ||
type: string; | ||
@@ -101,3 +101,3 @@ entityType: string; | ||
relation: string; | ||
compare: Compare<T>; | ||
compare: Compare; | ||
} | ||
@@ -135,4 +135,4 @@ export interface SetStateAction<S extends State> { | ||
export declare type MoveAttachedActionCreator = (entityType: string, id: Id, relation: string, src: number, dest: number) => MoveAttachedAction | InvalidAction; | ||
export declare type SortActionCreator = <T extends Entity = Entity>(entityType: string, compare: Compare<T>) => SortAction<T> | InvalidAction; | ||
export declare type SortAttachedActionCreator = <T extends Entity = Entity>(entityType: string, id: Id, relation: string, compare: Compare<T>) => SortAction<T> | InvalidAction; | ||
export declare type SortActionCreator = <T extends Entity = Entity>(entityType: string, compare: Compare<T>) => SortAction | InvalidAction; | ||
export declare type SortAttachedActionCreator = <T extends Entity = Entity>(entityType: string, id: Id, relation: string, compare: Compare<T>) => SortAction | InvalidAction; | ||
export declare type SetStateActionCreator<S extends State> = (state: S) => SetStateAction<S>; | ||
@@ -139,0 +139,0 @@ export declare type State = { |
@@ -1509,2 +1509,17 @@ 'use strict'; | ||
var fromNormalizr = function fromNormalizr(data) { | ||
var entitiesByType = data.entities; | ||
var state = { | ||
entities: {}, | ||
ids: {} | ||
}; | ||
Object.entries(entitiesByType).forEach(function (_ref) { | ||
var type = _ref[0], | ||
entities = _ref[1]; | ||
state.entities[type] = entities; | ||
state.ids[type] = Object.keys(entities); | ||
}); | ||
return state; | ||
}; | ||
var defaultNamespaced = function defaultNamespaced(actionType) { | ||
@@ -1541,2 +1556,3 @@ return "normalized/" + actionType; | ||
exports.default = makeNormalizedSlice; | ||
exports.fromNormalizr = fromNormalizr; | ||
//# sourceMappingURL=normalized-reducer.cjs.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function r(t){var r=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,r){if(t){if("string"==typeof t)return e(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?e(t,void 0):void 0}}(t)))return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}var i,n;Object.defineProperty(exports,"__esModule",{value:!0}),(i=exports.Cardinalities||(exports.Cardinalities={})).ONE="one",i.MANY="many",(n=exports.UpdateActionMethod||(exports.UpdateActionMethod={})).PUT="put",n.PATCH="patch";var a=function(t,e,r){if(!e)return[t];var i=[].concat(e);return void 0===r?i.push(t):i.splice(r,0,t),i};function o(t,e,r){if(e<0||r<0)return t;e=e>t.length-1?t.length-1:e;var i=[].concat(t),n=i[e];return i.splice(e,1),i.splice(r,0,n),i}var s=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&"function"!=typeof t},c=function(t,e,r){return"object"==typeof t?Object.keys(t).reduce((function(i,n){return e.type(r).hasRelationKey(n)||(i[n]=t[n]),i}),{}):{}},y=function(){function t(t){var e=this;!function(t){if(!s(t))throw new Error("schema must be an object literal");Object.entries(t).forEach((function(e){var r=e[0],i=e[1];if(!s(i))throw new Error('schema of type "'+r+'" must be an object literal');Object.entries(i).forEach((function(e){var i=e[0],n=e[1];if(!s(n))throw new Error('schema of type "'+r+'" relation "'+i+'" must be an object literal');if(!n.hasOwnProperty("type"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "type" attribute');if(!t.hasOwnProperty(n.type))throw new Error('schema of type "'+r+'" relation "'+i+'" relates to type "'+n.type+'", but type "'+n.type+'" does not have an entity schema of its own');if(!n.hasOwnProperty("cardinality"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "cardinality" attribute');if(n.cardinality!==exports.Cardinalities.MANY&&n.cardinality!==exports.Cardinalities.ONE)throw new Error('schema of type "'+r+'" relation "'+i+'" cardinality must be either "'+exports.Cardinalities.ONE+'" or "'+exports.Cardinalities.MANY+'"');if(!n.hasOwnProperty("reciprocal"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "reciprocal" attribute');if(!t[n.type][n.reciprocal])throw new Error('schema of type "'+r+'" relation "'+i+'" has a reciprocal of "'+n.reciprocal+'" on type "'+n.type+'", but "'+n.type+'" does not have a relation "'+n.reciprocal+'"');if(t[n.type][n.reciprocal]&&t[n.type][n.reciprocal].reciprocal!==i)throw new Error('schema of type "'+r+'" relation "'+i+'" has a reciprocal of "'+n.reciprocal+'" on type "'+n.type+'", but "'+n.reciprocal+'" does not point back to "'+i+'"')}))}))}(t),this.schema=t,this.entitySchemaReaders=Object.entries(t).reduce((function(t,r){var i=r[0];return t[i]=new p(i,r[1],e),t}),{})}var e=t.prototype;return e.typeExists=function(t){return this.getEntities().includes(t)},e.type=function(t){return this.entitySchemaReaders[t]},e.getEntities=function(){return Object.keys(this.schema)},e.getEmptyEntitiesByTypeState=function(){return this.emptyEntitiesByTypeState||(this.emptyEntitiesByTypeState=this.getEntities().reduce((function(t,e){return t[e]={},t}),{})),this.emptyEntitiesByTypeState},e.getEmptyIdsByTypeState=function(){return this.emptyIdsByTypeState||(this.emptyIdsByTypeState=this.getEntities().reduce((function(t,e){return t[e]=[],t}),{})),this.emptyIdsByTypeState},e.getEmptyState=function(){return this.emptyState||(this.emptyState={entities:this.getEmptyEntitiesByTypeState(),ids:this.getEmptyIdsByTypeState()}),this.emptyState},t}(),p=function(){function t(t,e,r){this.type=t,this.schema=e,this.modelSchemaReader=r}var e=t.prototype;return e.getType=function(){return this.type},e.hasRelationKey=function(t){return this.getRelationKeys().includes(t)},e.resolveRelationKey=function(t){if(this.hasRelationKey(t))return t;for(var e,i=t,n=void 0,a=r(this.getRelationKeys());!(e=a()).done;){var o=e.value;if(this.getRelationSchema(o).type===i){if(n)return;n=o}}return n},e.resolveRelationType=function(t){if(this.hasRelationKey(t))return this.getRelationType(t);for(var e,i=t,n=r(this.relationSchemas());!(e=n()).done;)if(e.value.type===i)return i},e.resolveRelationCardinality=function(t){var e=this.resolveRelationKey(t);if(e)return this.getRelationCardinality(e)},e.resolveRelationReciprocalKey=function(t){var e=this.resolveRelationKey(t);if(e)return this.getRelationReciprocalKey(e)},e.resolveReciprocalCardinality=function(t){var e=this.resolveRelationKey(t);if(e){var r=this.getRelationType(e),i=this.getRelationReciprocalKey(e);if(r&&i)return this.modelSchemaReader.type(r).getRelationCardinality(i)}},e.getRelationKeys=function(){return Object.keys(this.schema)},e.relationSchemas=function(){return Object.values(this.schema)},e.getRelationSchema=function(t){return this.schema[t]},e.getRelationCardinality=function(t){return this.getRelationSchemaField(t,"cardinality")},e.getRelationType=function(t){return this.getRelationSchemaField(t,"type")},e.getRelationReciprocalKey=function(t){return this.getRelationSchemaField(t,"reciprocal")},e.getEmptyEntityState=function(t){return t?Object.entries(this.schema).reduce((function(t,e){var r=e[0],i=e[1];return i.cardinality===exports.Cardinalities.ONE&&(t[r]=void 0),i.cardinality===exports.Cardinalities.MANY&&(t[r]=[]),t}),{}):{}},e.getEmptyRelationState=function(t){return this.getRelationCardinality(t)===exports.Cardinalities.ONE?void 0:[]},e.getRelationSchemaField=function(t,e){var r=this.getRelationSchema(t);if(r)return r[e]},t}(),u=[],l={},d=function(t){return'Entity-type "'+t+'" does not exist'},f=function(t,e){return'Entity "'+t+'" does not have a relation named "'+e+'"'},h=function(t){return t+" index is less than 0"},v=function(){function t(t){this.actionTypes=t}var e=t.prototype;return e.isHandleable=function(t){return Object.values(this.actionTypes).includes(t.type)},e.isDerivable=function(t){var e=this.actionTypes;return[e.DETACH,e.DELETE,e.ATTACH].includes(t.type)},e.isBatch=function(t){return t.type===this.actionTypes.BATCH},e.isStateSetter=function(t){return t.type===this.actionTypes.SET_STATE},t}(),T=function(){function t(t,e,r,i){this.actionTypes=t,this.actionCreators=e,this.schema=r,this.selectors=i}var e=t.prototype;return e.deriveAction=function(t,e){var r=this;if(e.type===this.actionTypes.DETACH){var i=this.deriveDetachActions(e);return{type:e.type,original:e,derived:i}}if(e.type===this.actionTypes.ATTACH){var n=this.deriveAttachActions(t,e);return{type:e.type,original:e,derived:n}}if(e.type===this.actionTypes.DELETE){var a=e,o=[];if(a.cascade||(o=this.deriveDeleteActions(t,a)),a.cascade){var s,c=this.selectors.getEntityTree(t,{type:a.entityType,id:a.id,schema:a.cascade}),y=[];c.forEach((function(e){var i=r.actionCreators.delete(e.type,e.id);i.type===r.actionTypes.DELETE&&y.push.apply(y,r.deriveDeleteActions(t,i))})),(s=o).push.apply(s,y)}return{type:e.type,original:e,derived:o}}return e},e.deriveDetachActions=function(t){var e=t.id,r=t.relation,i=t.detachableId,n=this.schema.type(t.entityType),a=n.resolveRelationType(r),o=n.resolveRelationReciprocalKey(r);return a&&o?[t,this.actionCreators.detach(a,i,o,e)]:[t]},e.deriveAttachActions=function(t,e){var r=e.entityType,i=e.id,n=e.relation,a=e.attachableId,o=this.schema.type(r),s=o.resolveRelationType(n);if(!s)return[];if(!this.selectors.getEntity(t,{type:r,id:i}))return[];var c=this.selectors.getEntity(t,{type:s,id:a}),y=o.resolveRelationReciprocalKey(n);if(!c||!y)return[];var p=this.actionCreators.attach(s,a,y,i,{index:e.reciprocalIndex,reciprocalIndex:e.index}),u=this.detachOccupant(t,r,i,n),l=this.detachOccupant(t,s,a,y);return[e,p].concat(u,l)},e.deriveDeleteActions=function(t,e){var r=this,i=e.entityType,n=e.id,a=this.schema.type(i);if(!a)return[];var o=this.selectors.getAllAttachedIds(t,{type:i,id:n}),s=Object.entries(o).reduce((function(t,e){var i=e[0],o=e[1],s=a.resolveRelationType(i);if(!s)return t;var c=a.resolveRelationReciprocalKey(i);if(!c)return t;var y=o.map((function(t){return r.actionCreators.detach(s,t,c,n)}));return t.push.apply(t,y),t}),[]);return[e].concat(s)},e.detachOccupant=function(t,e,r,i){var n=this.schema.type(e),a=n.resolveRelationType(i),o=n.resolveRelationReciprocalKey(i),s=n.resolveRelationCardinality(i);if(!a||!o||s===exports.Cardinalities.MANY)return[];var c=this.selectors.getAttached(t,{type:e,id:r,relation:i});return c?[this.actionCreators.detach(e,r,a,c),this.actionCreators.detach(a,c,o,r)]:[]},t}(),E=function(t){return"normalized/"+t};exports.default=function(e,i){void 0===i&&(i=E);var n=new y(e),s=function(t,e){var r=e("BATCH"),i=e("INVALID"),n=e("ATTACH"),a=e("DETACH"),o=e("DELETE"),s=e("CREATE"),y=e("UPDATE"),p=e("MOVE"),u=e("MOVE_ATTACHED"),l=e("SORT"),T=e("SORT_ATTACHED"),E=e("SET_STATE"),A=function(t,e){return{type:i,error:e,action:t}},m={BATCH:r,INVALID:i,ATTACH:n,DETACH:a,DELETE:o,CREATE:s,UPDATE:y,MOVE:p,MOVE_ATTACHED:u,SORT:l,SORT_ATTACHED:T,SET_STATE:E};return{actionTypes:m,actionCreators:{batch:function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return{type:r,actions:e}},attach:function(e,r,i,a,o){void 0===o&&(o={});var s={type:n,entityType:e,id:r,relation:i,attachableId:a,index:o.index,reciprocalIndex:o.reciprocalIndex};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?s:A(s,f(e,i)):A(s,d(e))},detach:function(e,r,i,n){var o={type:a,entityType:e,id:r,relation:i,detachableId:n};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?o:A(o,f(e,i)):A(o,d(e))},delete:function(e,r,i){var n={type:o,entityType:e,id:r,cascade:i};return t.typeExists(e)?n:A(n,d(e))},create:function(e,r,i,n){void 0===i&&(i={});var a={type:s,entityType:e,id:r,data:i,index:n};return t.typeExists(e)?(a.data=c(i,t,e),a):A(a,d(e))},update:function(e,r,i,n){void 0===n&&(n={});var a={type:y,entityType:e,id:r,data:i,method:n.method||exports.UpdateActionMethod.PATCH};return t.typeExists(e)?(a.data=c(i,t,e),a):A(a,d(e))},move:function(e,r,i){var n={type:p,entityType:e,src:r,dest:i};return t.typeExists(e)?r<0?A(n,h("source")):i<0?A(n,h("destination")):n:A(n,d(e))},moveAttached:function(e,r,i,n,a){var o={type:u,entityType:e,id:r,relation:i,src:n,dest:a};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?n<0?A(o,h("source")):a<0?A(o,h("destination")):o:A(o,f(e,i)):A(o,d(e))},sort:function(e,r){var i={type:l,entityType:e,compare:r};return t.typeExists(e)?i:A(i,d(e))},sortAttached:function(e,r,i,n){var a={type:T,entityType:e,id:r,relation:i,compare:n};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?a:A(a,f(e,i)):A(a,d(e))},setState:function(t){return{type:E,state:t}}},actionUtils:new v(m)}}(n,i),p=s.actionTypes,A=s.actionCreators,m=s.actionUtils,R=function(t){var e=function(e,r){return t.typeExists(r.type)&&e.entities[r.type]||l},i=function(r,i){if(t.typeExists(i.type))return e(r,i)[i.id]},n=function(e,r){var n=t.type(r.type);if(n){var a=n.resolveRelationKey(r.relation);if(a){var o=i(e,r);if(o)return o[a]}}},a=function(e,r){var i=r.type,a=r.id,o=r.relation,s=t.type(i).resolveRelationKey(o);if(!s)return[];var c=n(e,{type:i,id:a,relation:s});return c&&"string"==typeof c?[c]:c&&Array.isArray(c)?c:[]};return{getIds:function(e,r){return t.typeExists(r.type)&&e.ids[r.type]||u},getEntities:e,getEntity:i,getAttached:n,getAllAttachedIds:function(e,i){var n=i.type,o=i.id,s=t.type(n);if(!s)return{};for(var c,y={},p=r(s.getRelationKeys());!(c=p()).done;){var u=c.value,l=a(e,{type:n,id:o,relation:u});l.length&&(y[u]=l)}return y},getEntityTree:function(e,n){var o=n.type,s=n.id,c=n.schema;if(!t.type(o))return[];if(!i(e,{type:o,id:s}))return[];var y=function e(n,o,s,c,y){void 0===y&&(y={});var p=i(n,{type:o,id:s});if(!p)return y;y[o+"."+s]={id:s,type:o,entity:p},"function"==typeof c&&(c=c());for(var u=0,l=Object.entries(c);u<l.length;u++){var d=l[u],f=d[0],h=d[1],v=t.type(o).resolveRelationKey(f),T=t.type(o).resolveRelationType(f);if(v&&T)for(var E,A=r(a(n,{type:o,id:s,relation:v}));!(E=A()).done;)e(n,T,E.value,h,y)}return y}(e,o,s,c);return Object.values(y)}}}(n),g=function(t){return{getIds:t.getIds,getEntities:t.getEntities,getEntity:t.getEntity}}(R);return{emptyState:n.getEmptyState(),selectors:g,actionTypes:p,actionCreators:A,reducer:function(e,r,i,n){function s(e,a){var o=a;return(n.isDerivable(o)?r.deriveAction(e,o).derived:[o]).reduce((function(e,r){if(r.type===i.SORT){var n,a=r.entityType,o=r.compare,s=e.entities[a],c=[].concat(e.ids[a]).sort((function(t,e){return o(s[t],s[e])}));return{entities:e.entities,ids:t({},e.ids,(n={},n[a]=c,n))}}return{entities:y(e.entities,r),ids:u(e.ids,r)}}),e)}var c=e.getEmptyEntitiesByTypeState();function y(r,n){if(void 0===r&&(r=c),n.type===i.INVALID)return r;if(!e.typeExists(n.entityType))return r;if(n.type===i.DETACH){var s,y,p=n.entityType,u=n.id,l=n.detachableId,d=n.relation,f=r[p][u];if(!f)return r;var h=e.type(p).resolveRelationKey(d);if(!h)return r;var v,T=f,E=e.type(p).resolveRelationCardinality(d);if(E===exports.Cardinalities.ONE){var A;if(l!==f[h])return r;T=t({},f,((A={})[h]=void 0,A))}return E===exports.Cardinalities.MANY&&(T=t({},f,((v={})[h]=f[h].filter((function(t){return t!==l})),v))),t({},r,((y={})[p]=t({},r[p],((s={})[u]=T,s)),y))}if(n.type===i.ATTACH){var m,R,g=n.entityType,C=n.id,S=n.attachableId,b=n.relation,x=n.index,O=r[g][C];if(!O)return r;var w=e.type(g).resolveRelationKey(b);if(!w)return r;var D,I,K=O,H=e.type(g).resolveRelationCardinality(b);return H===exports.Cardinalities.ONE&&(K=t({},K,((D={})[w]=S,D))),H===exports.Cardinalities.MANY&&(O[w]&&O[w].includes(S)||(K=t({},K,((I={})[w]=a(S,K[w],x),I)))),t({},r,((R={})[g]=t({},r[g],((m={})[C]=K,m)),R))}if(n.type===i.DELETE){var j,M=n.entityType,N=n.id;if(!r[M][N])return r;var B=t({},r[M]);return delete B[N],t({},r,((j={})[M]=B,j))}if(n.type===i.CREATE){var P,U,_=n.entityType,L=n.id;return r[_][L]?r:t({},r,((U={})[_]=t({},r[_],((P={})[L]=n.data||{},P)),U))}if(n.type===i.UPDATE){var V,Y,k=n.entityType,F=n.id,z=n.data,$=n.method,q=r[k][F];if(!q)return r;var G=t({},q);return $===exports.UpdateActionMethod.PUT&&(G=t({},z,{},e.type(k).getRelationKeys().reduce((function(t,e){return q[e]&&(t[e]=q[e]),t}),{}))),$===exports.UpdateActionMethod.PATCH&&(G=t({},q,{},z)),t({},r,((Y={})[k]=t({},r[k],((V={})[F]=G,V)),Y))}if(n.type===i.MOVE_ATTACHED){var J,Q,W,X=n.entityType,Z=n.id,tt=n.relation,et=n.src,rt=n.dest,it=r[X][Z];if(!it)return r;var nt=e.type(X).resolveRelationKey(tt);if(!nt)return r;if(e.type(X).resolveRelationCardinality(tt)===exports.Cardinalities.ONE)return r;var at=it[nt];if(!Array.isArray(at))return r;var ot=t({},it,((J={})[nt]=o(at,et,rt),J));return t({},r,((W={})[X]=t({},r[X],((Q={})[Z]=ot,Q)),W))}if(n.type===i.SORT_ATTACHED){var st,ct,yt,pt=n.entityType,ut=n.id,lt=n.relation,dt=n.compare,ft=r[pt][ut];if(!ft)return r;var ht=e.type(pt).resolveRelationKey(lt),vt=e.type(pt).resolveRelationType(lt);if(!ht||!vt)return r;if(e.type(pt).resolveRelationCardinality(lt)===exports.Cardinalities.ONE)return r;var Tt=ft[ht];if(!Array.isArray(Tt))return r;var Et=r[vt],At=[].concat(Tt).sort((function(t,e){return dt(Et[t],Et[e])})),mt=t({},ft,((st={})[ht]=At,st));return t({},r,((yt={})[pt]=t({},r[pt],((ct={})[ut]=mt,ct)),yt))}return r}var p=e.getEmptyIdsByTypeState();function u(r,n){if(void 0===r&&(r=p),n.type===i.INVALID)return r;if(!e.typeExists(n.entityType))return r;if(n.type===i.DELETE){var s,c=n.entityType,y=n.id,u=r[c].filter((function(t){return t!==y}));return t({},r,((s={})[c]=u,s))}if(n.type===i.CREATE){var l,d=n.entityType,f=n.id,h=n.index;return r[d].includes(f)?r:t({},r,((l={})[d]=a(f,r[d],h),l))}if(n.type===i.MOVE){var v,T=n.entityType;return t({},r,((v={})[T]=o(r[T],n.src,n.dest),v))}return r}return function(t,r){return void 0===t&&(t=e.getEmptyState()),n.isHandleable(r)?n.isStateSetter(r)&&r.type===i.SET_STATE?r.state:n.isBatch(r)?r.actions.reduce((function(t,e){return s(t,e)}),t):s(t,r):t}}(n,new T(p,A,n,R),p,m)}}; | ||
"use strict";function t(){return(t=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t}).apply(this,arguments)}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,i=new Array(e);r<e;r++)i[r]=t[r];return i}function r(t){var r=0;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(t=function(t,r){if(t){if("string"==typeof t)return e(t,void 0);var i=Object.prototype.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(i):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?e(t,void 0):void 0}}(t)))return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(r=t[Symbol.iterator]()).next.bind(r)}var i,n;Object.defineProperty(exports,"__esModule",{value:!0}),(i=exports.Cardinalities||(exports.Cardinalities={})).ONE="one",i.MANY="many",(n=exports.UpdateActionMethod||(exports.UpdateActionMethod={})).PUT="put",n.PATCH="patch";var a=function(t,e,r){if(!e)return[t];var i=[].concat(e);return void 0===r?i.push(t):i.splice(r,0,t),i};function o(t,e,r){if(e<0||r<0)return t;e=e>t.length-1?t.length-1:e;var i=[].concat(t),n=i[e];return i.splice(e,1),i.splice(r,0,n),i}var s=function(t){return"object"==typeof t&&null!==t&&!Array.isArray(t)&&"function"!=typeof t},c=function(t,e,r){return"object"==typeof t?Object.keys(t).reduce((function(i,n){return e.type(r).hasRelationKey(n)||(i[n]=t[n]),i}),{}):{}},y=function(){function t(t){var e=this;!function(t){if(!s(t))throw new Error("schema must be an object literal");Object.entries(t).forEach((function(e){var r=e[0],i=e[1];if(!s(i))throw new Error('schema of type "'+r+'" must be an object literal');Object.entries(i).forEach((function(e){var i=e[0],n=e[1];if(!s(n))throw new Error('schema of type "'+r+'" relation "'+i+'" must be an object literal');if(!n.hasOwnProperty("type"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "type" attribute');if(!t.hasOwnProperty(n.type))throw new Error('schema of type "'+r+'" relation "'+i+'" relates to type "'+n.type+'", but type "'+n.type+'" does not have an entity schema of its own');if(!n.hasOwnProperty("cardinality"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "cardinality" attribute');if(n.cardinality!==exports.Cardinalities.MANY&&n.cardinality!==exports.Cardinalities.ONE)throw new Error('schema of type "'+r+'" relation "'+i+'" cardinality must be either "'+exports.Cardinalities.ONE+'" or "'+exports.Cardinalities.MANY+'"');if(!n.hasOwnProperty("reciprocal"))throw new Error('schema of type "'+r+'" relation "'+i+'" is missing "reciprocal" attribute');if(!t[n.type][n.reciprocal])throw new Error('schema of type "'+r+'" relation "'+i+'" has a reciprocal of "'+n.reciprocal+'" on type "'+n.type+'", but "'+n.type+'" does not have a relation "'+n.reciprocal+'"');if(t[n.type][n.reciprocal]&&t[n.type][n.reciprocal].reciprocal!==i)throw new Error('schema of type "'+r+'" relation "'+i+'" has a reciprocal of "'+n.reciprocal+'" on type "'+n.type+'", but "'+n.reciprocal+'" does not point back to "'+i+'"')}))}))}(t),this.schema=t,this.entitySchemaReaders=Object.entries(t).reduce((function(t,r){var i=r[0];return t[i]=new p(i,r[1],e),t}),{})}var e=t.prototype;return e.typeExists=function(t){return this.getEntities().includes(t)},e.type=function(t){return this.entitySchemaReaders[t]},e.getEntities=function(){return Object.keys(this.schema)},e.getEmptyEntitiesByTypeState=function(){return this.emptyEntitiesByTypeState||(this.emptyEntitiesByTypeState=this.getEntities().reduce((function(t,e){return t[e]={},t}),{})),this.emptyEntitiesByTypeState},e.getEmptyIdsByTypeState=function(){return this.emptyIdsByTypeState||(this.emptyIdsByTypeState=this.getEntities().reduce((function(t,e){return t[e]=[],t}),{})),this.emptyIdsByTypeState},e.getEmptyState=function(){return this.emptyState||(this.emptyState={entities:this.getEmptyEntitiesByTypeState(),ids:this.getEmptyIdsByTypeState()}),this.emptyState},t}(),p=function(){function t(t,e,r){this.type=t,this.schema=e,this.modelSchemaReader=r}var e=t.prototype;return e.getType=function(){return this.type},e.hasRelationKey=function(t){return this.getRelationKeys().includes(t)},e.resolveRelationKey=function(t){if(this.hasRelationKey(t))return t;for(var e,i=t,n=void 0,a=r(this.getRelationKeys());!(e=a()).done;){var o=e.value;if(this.getRelationSchema(o).type===i){if(n)return;n=o}}return n},e.resolveRelationType=function(t){if(this.hasRelationKey(t))return this.getRelationType(t);for(var e,i=t,n=r(this.relationSchemas());!(e=n()).done;)if(e.value.type===i)return i},e.resolveRelationCardinality=function(t){var e=this.resolveRelationKey(t);if(e)return this.getRelationCardinality(e)},e.resolveRelationReciprocalKey=function(t){var e=this.resolveRelationKey(t);if(e)return this.getRelationReciprocalKey(e)},e.resolveReciprocalCardinality=function(t){var e=this.resolveRelationKey(t);if(e){var r=this.getRelationType(e),i=this.getRelationReciprocalKey(e);if(r&&i)return this.modelSchemaReader.type(r).getRelationCardinality(i)}},e.getRelationKeys=function(){return Object.keys(this.schema)},e.relationSchemas=function(){return Object.values(this.schema)},e.getRelationSchema=function(t){return this.schema[t]},e.getRelationCardinality=function(t){return this.getRelationSchemaField(t,"cardinality")},e.getRelationType=function(t){return this.getRelationSchemaField(t,"type")},e.getRelationReciprocalKey=function(t){return this.getRelationSchemaField(t,"reciprocal")},e.getEmptyEntityState=function(t){return t?Object.entries(this.schema).reduce((function(t,e){var r=e[0],i=e[1];return i.cardinality===exports.Cardinalities.ONE&&(t[r]=void 0),i.cardinality===exports.Cardinalities.MANY&&(t[r]=[]),t}),{}):{}},e.getEmptyRelationState=function(t){return this.getRelationCardinality(t)===exports.Cardinalities.ONE?void 0:[]},e.getRelationSchemaField=function(t,e){var r=this.getRelationSchema(t);if(r)return r[e]},t}(),u=[],l={},d=function(t){return'Entity-type "'+t+'" does not exist'},f=function(t,e){return'Entity "'+t+'" does not have a relation named "'+e+'"'},h=function(t){return t+" index is less than 0"},v=function(){function t(t){this.actionTypes=t}var e=t.prototype;return e.isHandleable=function(t){return Object.values(this.actionTypes).includes(t.type)},e.isDerivable=function(t){var e=this.actionTypes;return[e.DETACH,e.DELETE,e.ATTACH].includes(t.type)},e.isBatch=function(t){return t.type===this.actionTypes.BATCH},e.isStateSetter=function(t){return t.type===this.actionTypes.SET_STATE},t}(),T=function(){function t(t,e,r,i){this.actionTypes=t,this.actionCreators=e,this.schema=r,this.selectors=i}var e=t.prototype;return e.deriveAction=function(t,e){var r=this;if(e.type===this.actionTypes.DETACH){var i=this.deriveDetachActions(e);return{type:e.type,original:e,derived:i}}if(e.type===this.actionTypes.ATTACH){var n=this.deriveAttachActions(t,e);return{type:e.type,original:e,derived:n}}if(e.type===this.actionTypes.DELETE){var a=e,o=[];if(a.cascade||(o=this.deriveDeleteActions(t,a)),a.cascade){var s,c=this.selectors.getEntityTree(t,{type:a.entityType,id:a.id,schema:a.cascade}),y=[];c.forEach((function(e){var i=r.actionCreators.delete(e.type,e.id);i.type===r.actionTypes.DELETE&&y.push.apply(y,r.deriveDeleteActions(t,i))})),(s=o).push.apply(s,y)}return{type:e.type,original:e,derived:o}}return e},e.deriveDetachActions=function(t){var e=t.id,r=t.relation,i=t.detachableId,n=this.schema.type(t.entityType),a=n.resolveRelationType(r),o=n.resolveRelationReciprocalKey(r);return a&&o?[t,this.actionCreators.detach(a,i,o,e)]:[t]},e.deriveAttachActions=function(t,e){var r=e.entityType,i=e.id,n=e.relation,a=e.attachableId,o=this.schema.type(r),s=o.resolveRelationType(n);if(!s)return[];if(!this.selectors.getEntity(t,{type:r,id:i}))return[];var c=this.selectors.getEntity(t,{type:s,id:a}),y=o.resolveRelationReciprocalKey(n);if(!c||!y)return[];var p=this.actionCreators.attach(s,a,y,i,{index:e.reciprocalIndex,reciprocalIndex:e.index}),u=this.detachOccupant(t,r,i,n),l=this.detachOccupant(t,s,a,y);return[e,p].concat(u,l)},e.deriveDeleteActions=function(t,e){var r=this,i=e.entityType,n=e.id,a=this.schema.type(i);if(!a)return[];var o=this.selectors.getAllAttachedIds(t,{type:i,id:n}),s=Object.entries(o).reduce((function(t,e){var i=e[0],o=e[1],s=a.resolveRelationType(i);if(!s)return t;var c=a.resolveRelationReciprocalKey(i);if(!c)return t;var y=o.map((function(t){return r.actionCreators.detach(s,t,c,n)}));return t.push.apply(t,y),t}),[]);return[e].concat(s)},e.detachOccupant=function(t,e,r,i){var n=this.schema.type(e),a=n.resolveRelationType(i),o=n.resolveRelationReciprocalKey(i),s=n.resolveRelationCardinality(i);if(!a||!o||s===exports.Cardinalities.MANY)return[];var c=this.selectors.getAttached(t,{type:e,id:r,relation:i});return c?[this.actionCreators.detach(e,r,a,c),this.actionCreators.detach(a,c,o,r)]:[]},t}(),E=function(t){return"normalized/"+t};exports.default=function(e,i){void 0===i&&(i=E);var n=new y(e),s=function(t,e){var r=e("BATCH"),i=e("INVALID"),n=e("ATTACH"),a=e("DETACH"),o=e("DELETE"),s=e("CREATE"),y=e("UPDATE"),p=e("MOVE"),u=e("MOVE_ATTACHED"),l=e("SORT"),T=e("SORT_ATTACHED"),E=e("SET_STATE"),m=function(t,e){return{type:i,error:e,action:t}},A={BATCH:r,INVALID:i,ATTACH:n,DETACH:a,DELETE:o,CREATE:s,UPDATE:y,MOVE:p,MOVE_ATTACHED:u,SORT:l,SORT_ATTACHED:T,SET_STATE:E};return{actionTypes:A,actionCreators:{batch:function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return{type:r,actions:e}},attach:function(e,r,i,a,o){void 0===o&&(o={});var s={type:n,entityType:e,id:r,relation:i,attachableId:a,index:o.index,reciprocalIndex:o.reciprocalIndex};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?s:m(s,f(e,i)):m(s,d(e))},detach:function(e,r,i,n){var o={type:a,entityType:e,id:r,relation:i,detachableId:n};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?o:m(o,f(e,i)):m(o,d(e))},delete:function(e,r,i){var n={type:o,entityType:e,id:r,cascade:i};return t.typeExists(e)?n:m(n,d(e))},create:function(e,r,i,n){void 0===i&&(i={});var a={type:s,entityType:e,id:r,data:i,index:n};return t.typeExists(e)?(a.data=c(i,t,e),a):m(a,d(e))},update:function(e,r,i,n){void 0===n&&(n={});var a={type:y,entityType:e,id:r,data:i,method:n.method||exports.UpdateActionMethod.PATCH};return t.typeExists(e)?(a.data=c(i,t,e),a):m(a,d(e))},move:function(e,r,i){var n={type:p,entityType:e,src:r,dest:i};return t.typeExists(e)?r<0?m(n,h("source")):i<0?m(n,h("destination")):n:m(n,d(e))},moveAttached:function(e,r,i,n,a){var o={type:u,entityType:e,id:r,relation:i,src:n,dest:a};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?n<0?m(o,h("source")):a<0?m(o,h("destination")):o:m(o,f(e,i)):m(o,d(e))},sort:function(e,r){var i={type:l,entityType:e,compare:r};return t.typeExists(e)?i:m(i,d(e))},sortAttached:function(e,r,i,n){var a={type:T,entityType:e,id:r,relation:i,compare:n};return t.typeExists(e)?t.type(e).resolveRelationKey(i)?a:m(a,f(e,i)):m(a,d(e))},setState:function(t){return{type:E,state:t}}},actionUtils:new v(A)}}(n,i),p=s.actionTypes,m=s.actionCreators,A=s.actionUtils,R=function(t){var e=function(e,r){return t.typeExists(r.type)&&e.entities[r.type]||l},i=function(r,i){if(t.typeExists(i.type))return e(r,i)[i.id]},n=function(e,r){var n=t.type(r.type);if(n){var a=n.resolveRelationKey(r.relation);if(a){var o=i(e,r);if(o)return o[a]}}},a=function(e,r){var i=r.type,a=r.id,o=r.relation,s=t.type(i).resolveRelationKey(o);if(!s)return[];var c=n(e,{type:i,id:a,relation:s});return c&&"string"==typeof c?[c]:c&&Array.isArray(c)?c:[]};return{getIds:function(e,r){return t.typeExists(r.type)&&e.ids[r.type]||u},getEntities:e,getEntity:i,getAttached:n,getAllAttachedIds:function(e,i){var n=i.type,o=i.id,s=t.type(n);if(!s)return{};for(var c,y={},p=r(s.getRelationKeys());!(c=p()).done;){var u=c.value,l=a(e,{type:n,id:o,relation:u});l.length&&(y[u]=l)}return y},getEntityTree:function(e,n){var o=n.type,s=n.id,c=n.schema;if(!t.type(o))return[];if(!i(e,{type:o,id:s}))return[];var y=function e(n,o,s,c,y){void 0===y&&(y={});var p=i(n,{type:o,id:s});if(!p)return y;y[o+"."+s]={id:s,type:o,entity:p},"function"==typeof c&&(c=c());for(var u=0,l=Object.entries(c);u<l.length;u++){var d=l[u],f=d[0],h=d[1],v=t.type(o).resolveRelationKey(f),T=t.type(o).resolveRelationType(f);if(v&&T)for(var E,m=r(a(n,{type:o,id:s,relation:v}));!(E=m()).done;)e(n,T,E.value,h,y)}return y}(e,o,s,c);return Object.values(y)}}}(n),g=function(t){return{getIds:t.getIds,getEntities:t.getEntities,getEntity:t.getEntity}}(R);return{emptyState:n.getEmptyState(),selectors:g,actionTypes:p,actionCreators:m,reducer:function(e,r,i,n){function s(e,a){var o=a;return(n.isDerivable(o)?r.deriveAction(e,o).derived:[o]).reduce((function(e,r){if(r.type===i.SORT){var n,a=r.entityType,o=r.compare,s=e.entities[a],c=[].concat(e.ids[a]).sort((function(t,e){return o(s[t],s[e])}));return{entities:e.entities,ids:t({},e.ids,(n={},n[a]=c,n))}}return{entities:y(e.entities,r),ids:u(e.ids,r)}}),e)}var c=e.getEmptyEntitiesByTypeState();function y(r,n){if(void 0===r&&(r=c),n.type===i.INVALID)return r;if(!e.typeExists(n.entityType))return r;if(n.type===i.DETACH){var s,y,p=n.entityType,u=n.id,l=n.detachableId,d=n.relation,f=r[p][u];if(!f)return r;var h=e.type(p).resolveRelationKey(d);if(!h)return r;var v,T=f,E=e.type(p).resolveRelationCardinality(d);if(E===exports.Cardinalities.ONE){var m;if(l!==f[h])return r;T=t({},f,((m={})[h]=void 0,m))}return E===exports.Cardinalities.MANY&&(T=t({},f,((v={})[h]=f[h].filter((function(t){return t!==l})),v))),t({},r,((y={})[p]=t({},r[p],((s={})[u]=T,s)),y))}if(n.type===i.ATTACH){var A,R,g=n.entityType,C=n.id,S=n.attachableId,b=n.relation,x=n.index,O=r[g][C];if(!O)return r;var w=e.type(g).resolveRelationKey(b);if(!w)return r;var D,I,K=O,j=e.type(g).resolveRelationCardinality(b);return j===exports.Cardinalities.ONE&&(K=t({},K,((D={})[w]=S,D))),j===exports.Cardinalities.MANY&&(O[w]&&O[w].includes(S)||(K=t({},K,((I={})[w]=a(S,K[w],x),I)))),t({},r,((R={})[g]=t({},r[g],((A={})[C]=K,A)),R))}if(n.type===i.DELETE){var H,N=n.entityType,M=n.id;if(!r[N][M])return r;var B=t({},r[N]);return delete B[M],t({},r,((H={})[N]=B,H))}if(n.type===i.CREATE){var P,U,_=n.entityType,L=n.id;return r[_][L]?r:t({},r,((U={})[_]=t({},r[_],((P={})[L]=n.data||{},P)),U))}if(n.type===i.UPDATE){var V,Y,k=n.entityType,F=n.id,z=n.data,$=n.method,q=r[k][F];if(!q)return r;var G=t({},q);return $===exports.UpdateActionMethod.PUT&&(G=t({},z,{},e.type(k).getRelationKeys().reduce((function(t,e){return q[e]&&(t[e]=q[e]),t}),{}))),$===exports.UpdateActionMethod.PATCH&&(G=t({},q,{},z)),t({},r,((Y={})[k]=t({},r[k],((V={})[F]=G,V)),Y))}if(n.type===i.MOVE_ATTACHED){var J,Q,W,X=n.entityType,Z=n.id,tt=n.relation,et=n.src,rt=n.dest,it=r[X][Z];if(!it)return r;var nt=e.type(X).resolveRelationKey(tt);if(!nt)return r;if(e.type(X).resolveRelationCardinality(tt)===exports.Cardinalities.ONE)return r;var at=it[nt];if(!Array.isArray(at))return r;var ot=t({},it,((J={})[nt]=o(at,et,rt),J));return t({},r,((W={})[X]=t({},r[X],((Q={})[Z]=ot,Q)),W))}if(n.type===i.SORT_ATTACHED){var st,ct,yt,pt=n.entityType,ut=n.id,lt=n.relation,dt=n.compare,ft=r[pt][ut];if(!ft)return r;var ht=e.type(pt).resolveRelationKey(lt),vt=e.type(pt).resolveRelationType(lt);if(!ht||!vt)return r;if(e.type(pt).resolveRelationCardinality(lt)===exports.Cardinalities.ONE)return r;var Tt=ft[ht];if(!Array.isArray(Tt))return r;var Et=r[vt],mt=[].concat(Tt).sort((function(t,e){return dt(Et[t],Et[e])})),At=t({},ft,((st={})[ht]=mt,st));return t({},r,((yt={})[pt]=t({},r[pt],((ct={})[ut]=At,ct)),yt))}return r}var p=e.getEmptyIdsByTypeState();function u(r,n){if(void 0===r&&(r=p),n.type===i.INVALID)return r;if(!e.typeExists(n.entityType))return r;if(n.type===i.DELETE){var s,c=n.entityType,y=n.id,u=r[c].filter((function(t){return t!==y}));return t({},r,((s={})[c]=u,s))}if(n.type===i.CREATE){var l,d=n.entityType,f=n.id,h=n.index;return r[d].includes(f)?r:t({},r,((l={})[d]=a(f,r[d],h),l))}if(n.type===i.MOVE){var v,T=n.entityType;return t({},r,((v={})[T]=o(r[T],n.src,n.dest),v))}return r}return function(t,r){return void 0===t&&(t=e.getEmptyState()),n.isHandleable(r)?n.isStateSetter(r)&&r.type===i.SET_STATE?r.state:n.isBatch(r)?r.actions.reduce((function(t,e){return s(t,e)}),t):s(t,r):t}}(n,new T(p,m,n,R),p,A)}},exports.fromNormalizr=function(t){var e={entities:{},ids:{}};return Object.entries(t.entities).forEach((function(t){var r=t[0],i=t[1];e.entities[r]=i,e.ids[r]=Object.keys(i)})),e}; | ||
//# sourceMappingURL=normalized-reducer.cjs.production.min.js.map |
@@ -1509,2 +1509,17 @@ function _extends() { | ||
var fromNormalizr = function fromNormalizr(data) { | ||
var entitiesByType = data.entities; | ||
var state = { | ||
entities: {}, | ||
ids: {} | ||
}; | ||
Object.entries(entitiesByType).forEach(function (_ref) { | ||
var type = _ref[0], | ||
entities = _ref[1]; | ||
state.entities[type] = entities; | ||
state.ids[type] = Object.keys(entities); | ||
}); | ||
return state; | ||
}; | ||
var defaultNamespaced = function defaultNamespaced(actionType) { | ||
@@ -1541,3 +1556,3 @@ return "normalized/" + actionType; | ||
export default makeNormalizedSlice; | ||
export { Cardinalities, UpdateActionMethod }; | ||
export { Cardinalities, UpdateActionMethod, fromNormalizr }; | ||
//# sourceMappingURL=normalized-reducer.esm.js.map |
{ | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"license": "MIT", | ||
@@ -42,2 +42,3 @@ "main": "dist/index.js", | ||
"husky": "^4.2.3", | ||
"normalizr": "^3.6.0", | ||
"tsdx": "^0.13.1", | ||
@@ -44,0 +45,0 @@ "tslib": "^1.11.1", |
@@ -30,2 +30,3 @@ # Normalized Reducer [![Coverage Status](https://coveralls.io/repos/github/brietsparks/normalized-reducer/badge.svg?branch=master)](https://coveralls.io/github/brietsparks/normalized-reducer?branch=master) | ||
- [`getEntity`](https://github.com/brietsparks/normalized-reducer#getEntity) | ||
- [Normalizr Integration](https://github.com/brietsparks/normalized-reducer#normalizr-integration) | ||
- [LICENSE](https://github.com/brietsparks/normalized-reducer#license) | ||
@@ -148,3 +149,3 @@ | ||
## Top level API | ||
The top level API is a higher-order function that accepts a `schema` and an optional `namespaced` argument and returns a reducer, action creators, action types, selectors, and empty state. | ||
The top level default export is a higher-order function that accepts a `schema` and an optional `namespaced` argument and returns a reducer, action creators, action types, selectors, and empty state. | ||
``` | ||
@@ -727,3 +728,15 @@ makeNormalizedSlice<S>(schema: ModelSchema, namespaced?: Namespaced): { | ||
## Normalizr Integration | ||
The top level named export `fromNormalizr` takes normalized data produced by a normalizr [`normalize`](https://github.com/paularmstrong/normalizr/blob/master/docs/api.md#normalizedata-schema) call and returns state that can be fed into the reducer. | ||
Example: | ||
```js | ||
import { normalize } from 'normalizr' | ||
import { fromNormalizr } from 'normalized-reducer' | ||
const NormalizrOutput = normalize(denormalizedData, normalizrSchema); | ||
const initialState = fromNormalizr(normalizedData); | ||
``` | ||
## LICENSE | ||
MIT |
@@ -32,2 +32,3 @@ import { | ||
InvalidAction, | ||
SortAttachedAction, | ||
} from './interfaces'; | ||
@@ -216,3 +217,3 @@ import { ModelSchemaReader } from './schema'; | ||
compare, | ||
}; | ||
} as SortAction; | ||
@@ -238,3 +239,3 @@ if (!schema.typeExists(entityType)) { | ||
compare, | ||
}; | ||
} as SortAttachedAction; | ||
@@ -241,0 +242,0 @@ if (!schema.typeExists(entityType)) { |
@@ -30,3 +30,4 @@ import { Schema, Namespaced, State } from './interfaces'; | ||
export * from './enums'; | ||
export * from './normalizr'; | ||
export default makeNormalizedSlice; |
@@ -124,9 +124,9 @@ import { Cardinalities, UpdateActionMethod } from './enums'; | ||
export interface SortAction<T extends Entity = Entity> { | ||
export interface SortAction { | ||
type: string; | ||
entityType: string; | ||
compare: Compare<T>; | ||
compare: Compare; | ||
} | ||
export interface SortAttachedAction<T extends Entity = Entity> { | ||
export interface SortAttachedAction { | ||
type: string; | ||
@@ -136,3 +136,3 @@ entityType: string; | ||
relation: string; | ||
compare: Compare<T>; | ||
compare: Compare; | ||
} | ||
@@ -214,3 +214,3 @@ | ||
compare: Compare<T> | ||
) => SortAction<T> | InvalidAction; | ||
) => SortAction | InvalidAction; | ||
@@ -222,3 +222,3 @@ export type SortAttachedActionCreator = <T extends Entity = Entity>( | ||
compare: Compare<T> | ||
) => SortAction<T> | InvalidAction; | ||
) => SortAction | InvalidAction; | ||
@@ -225,0 +225,0 @@ export type SetStateActionCreator<S extends State> = (state: S) => SetStateAction<S>; |
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
440884
35
4537
740
7