redux-rails
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -14,14 +14,14 @@ { | ||
"dependencies": { | ||
"babel-core": "^6.21.0", | ||
"redux": "^3.6.0" | ||
}, | ||
"devDependencies": { | ||
"babel-loader": "^6.2.10", | ||
"babel-core": "^6.26.3", | ||
"babel-loader": "^7.1.5", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-3": "^6.17.0", | ||
"json-server": "^0.12.1", | ||
"json-server": "^0.14.2", | ||
"nock": "^9.0.2", | ||
"webpack": "^1.14.0" | ||
"webpack": "^4.41.2" | ||
} | ||
} |
@@ -5,4 +5,5 @@ const webpack = require("webpack"); | ||
module.exports = { | ||
mode: 'development', | ||
module: { | ||
loaders: [ | ||
rules: [ | ||
{ | ||
@@ -12,5 +13,2 @@ test: /\.(js|jsx)$/, | ||
exclude: /node_modules/, | ||
query: { | ||
presets: ['es2015', 'stage-3', 'react'] | ||
} | ||
} | ||
@@ -23,3 +21,3 @@ ] | ||
output: { | ||
path: "dist", | ||
path: path.join(__dirname, "dist"), | ||
filename: "index.js" | ||
@@ -34,4 +32,4 @@ }, | ||
}, | ||
extensions: ["", ".js", ".jsx"] | ||
extensions: [".js", ".jsx"] | ||
} | ||
} |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("redux")):"function"==typeof define&&define.amd?define(["redux"],t):"object"==typeof exports?exports["redux-rails"]=t(require("redux")):e["redux-rails"]=t(e.redux)}("undefined"!=typeof self?self:this,function(e){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var a=t[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,r),a.l=!0,a.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(o,a,function(t){return e[t]}.bind(null,a));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=0,a=(t.determinOptimisticUpdateSetting=function(e){var t=e.resourceConfig,r=e.config,o=e.defaultConfig,a=void 0===o?{}:o;return i(t.optimisticUpdateEnabled)?t.optimisticUpdateEnabled:i(r.resources.optimisticUpdateEnabled)?r.resources.optimisticUpdateEnabled:i(r.optimisticUpdateEnabled)?r.optimisticUpdateEnabled:!i(a.optimisticUpdateEnabled)||a.optimisticUpdateEnabled},t.determineResourceType=function(e){var t=e.controller;return"s"===t[t.length-1]?"collection":"member"}),i=(t.getResourceNameSpace=function(e){var t=e.config,r=e.resource,o=t.resources[r].controller;return"collection"===a({controller:o})?"models":"attributes"},t.getResourceIdAttribute=function(e){var t=e.config,r=e.resource;return t.resources[r].idAttribute||"id"},t.getUniqueClientId=function(){return++o},t.isBool=function(e){return"boolean"==typeof e});t.getConfig=function(e){var t=e.config,r=e.store;return"function"==typeof t?t(r):t}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.railsActions=t.middleWare=t.combineConfigs=t.apiReducer=void 0;var o=c(r(2)),a=c(r(3)),i=c(r(6)),n=c(r(7));function c(e){return e&&e.__esModule?e:{default:e}}t.apiReducer=a.default,t.combineConfigs=n.default,t.middleWare=o.default,t.railsActions=i.default},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){return function(e,t){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return function(e,t){var r=[],o=!0,a=!1,i=void 0;try{for(var n,c=e[Symbol.iterator]();!(o=(n=c.next()).done)&&(r.push(n.value),!t||r.length!==t);o=!0);}catch(e){a=!0,i=e}finally{try{!o&&c.return&&c.return()}finally{if(a)throw i}}return r}(e,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},n=r(0),c={},d={SHOW:"GET",INDEX:"GET",CREATE:"POST",UPDATE:"PUT",DESTROY:"DELETE"},s=function(e,t){return e+"="+encodeURIComponent(t)},u=function(e,t){return Array.isArray(t)?function(e,t){return t.map(function(t){return s(e+"[]",t)})}(e,t):s(e,t)},l=function(e){var t=e.baseUrl,r=e.controller,o=e.railsAction,a=e.data,i=e.queryParams,c=void 0===i?{}:i,s=(0,n.determineResourceType)({controller:r}),l=function(e){return e.includes("/:id/")}(r),f=function(){return l||"collection"===s&&"INDEX"!==o&&"CREATE"!==o?"/"+a.id:""},m=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments[1],r=Object.keys(e).filter(function(t){return void 0!==e[t]||null!==e[t]});return 0===r.length||"GET"!==d[t]?"":"?"+r.map(function(t){return u(t,e[t])}).join("&")}(c,o);return""+(l?(""+t+r).replace("/:id",f()):""+t+r+f())+m},f=function(e){var t=e.resource,r=p({resource:t});r.shift(),r.length>0&&b(r[0])},m=function(e){var t=e.store,r=e.resource,o=e.railsAction,a=e.error,i=e.id,n=e.cId,c=e.optimisticUpdateEnabled,d=e.reject,s={type:r+"."+o+"_ERROR",error:a,id:i,cId:n},u="CREATE"===o;t.dispatch(s),["CREATE","UPDATE"].includes(o)&&c&&t.dispatch({type:r+".UNSET_OPTIMISTIC_DATA",id:i,cId:n,destroy:u}),d(s)},b=function(e){var t=e.store,r=e.resource,o=e.config,a=e.data,c=void 0===a?{}:a,s=e.railsAction,u=e.controllerOverride,b=e.fetchParamsOverride,p=e.queryParamsOverride,y=e.resolve,g=e.reject,E=o.resources[r],I=E.baseUrl||o.baseUrl,A=u||E.controller,h=(0,n.getResourceIdAttribute)({config:o,resource:r}),M=b||E.fetchParams||o.fetchParams,S=p||E.queryParams||o.queryParams,D=function(e){var t=e.railsAction,r=(e.resource,e.config,e.data),o=e.fetchParams,a=void 0===o?{}:o,n=d[t],c=new Headers(a.headers||{}),s=Object.assign({},a,{method:n,headers:c});return"object"===(void 0===r?"undefined":i(r))&&"GET"!==n&&(s.body=JSON.stringify(r)),s}({railsAction:s,resource:r,data:c,config:o,fetchParams:M}),O=l({baseUrl:I,controller:A,railsAction:s,data:c,fetchParams:M,queryParams:S}),_=(0,n.determinOptimisticUpdateSetting)({resourceConfig:E,config:o}),T=void 0;"CREATE"===s&&(T=(0,n.getUniqueClientId)(),t.dispatch({type:r+".ASSIGN_CID",cId:T}),t.dispatch({type:r+".SET_LOADING",cId:T})),["CREATE","UPDATE"].includes(s)&&_&&t.dispatch({type:r+".SET_OPTIMISTIC_DATA",id:c.id,cId:T,data:c}),fetch(O,D).then(function(e){e.json().then(function(a){var i=a&&a[h]||c.id;if(!e.ok)return m({store:t,resource:r,railsAction:s,id:i,cId:T,optimisticUpdateEnabled:_,reject:g,error:a.error||{message:e.statusText}});!function(e){var t=e.store,r=e.resource,o=e.railsAction,a=e.id,i=e.cId,c=e.json,d=e.config,s=e.controller,u=e.resolve,l=r+"."+o+"_SUCCESS",f=v({json:c,resource:r,config:d,resourceType:(0,n.determineResourceType)({controller:s})}),m=f.response,b={cId:i,id:a,metaData:f.metaData,response:m,type:l};t.dispatch(b),u(b)}({store:t,resource:r,railsAction:s,id:i,cId:T,json:a,config:o,controller:A,optimisticUpdateEnabled:_,resolve:y})}).catch(function(e){var o=e&&e.toString&&e.toString();m({store:t,resource:r,railsAction:s,error:o,id:c.id,cId:T,optimisticUpdateEnabled:_,reject:g})})}).catch(function(e){m({store:t,resource:r,railsAction:s,error:e,id:c.id,cId:T,optimisticUpdateEnabled:_,reject:g})}).then(function(){return f({resource:r})})},p=function(e){var t=e.resource;return c[t]||(c[t]={queue:[]}),c[t].queue},v=function(e){var t=e.json,r=e.resource,o=e.config,a=e.resourceType,n=o.resources[r].parse,c=o.resources[r].setMetadata,d=void 0,s={};switch(void 0===n?"undefined":i(n)){case"object":var u=n&&n[a];if(!u){d=t;break}d=u(t);break;case"function":d=n(t);break;default:d=t}switch(void 0===c?"undefined":i(c)){case"object":var l=c&&c[a];if(!l)break;s=l(t);break;case"function":s=c(t);break;default:s={}}return{response:d,metaData:s}},y=function(e){var t=e.action,r=e.config,o=e.fetchData,i=e.next,n=e.resource,c=e.resourceConfig,d=new Promise(function(e,t){var i=a({resolve:e,reject:t},o);(r.disableFetchQueueing||c.disableFetchQueueing)&&b(i),function(e,t){var r=p({resource:e});r.push(t),r.length<=1&&b(t)}(n,i)});return i(t),d};t.default=function(e){return function(t){return function(r){return function(a){var i=(0,n.getConfig)({config:e,store:t.getState()}),c=a.type.split("."),s=o(c,2),u=s[0],l=s[1],f=a.data,m=a.controller,b=a.fetchParams,p=(f||{}).queryParams,v={store:t,resource:u,config:i,data:f,railsAction:l,controllerOverride:m,fetchParamsOverride:b,queryParamsOverride:p},g=i.resources[u];return g&&d[l]?y({action:a,config:i,fetchData:v,next:r,resource:u,resourceConfig:g}):r(a)}}}}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},a=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},i=r(4),n=r(5),c=r(0);function d(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}t.default=function(e){var t=(0,c.getConfig)({config:e}),r={};return Object.keys(t.resources).forEach(function(e){r[e]=function(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,n.getInitialState)({config:t,resource:e}),i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=t.resources[e]||{},u="attributes"===(0,c.getResourceNameSpace)({config:t,resource:e}),l=(0,c.getResourceIdAttribute)({config:t,resource:e}),f=(i.data||{}).queryParams;switch(i.type){case e+".INDEX":var m=s.paginated;return a({},r,(0,n.createNewCollection)({metaData:{loading:!0,queryParams:f},models:m?r.models:[]}));case e+".INDEX_SUCCESS":var b=i.response,p=i.metaData,v=i.response[e]||i.response[e.toLowerCase()];if(!Array.isArray(i.response)){if(!v||!Array.isArray(v))return console.error("Response to INDEX actions must be of type array OR contain a top-level key matching the resource name with an array as the value. You can use the parse method(s) set in your config for this resource to transform returned data if needed."),a({},r,(0,n.createNewCollection)({metaData:{loading:!1,loadingError:"Bad data received from server. INDEX calls expect an array."}}));b=v}return s.paginated&&function(){var e=b.reduce(function(e,t){return a({},e,function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}({},t.id,!0))},{});b=[].concat(d(r.models.map(function(e){return e.attributes}).filter(function(t){return!e[t.id]})),d(b))}(),a({},r,(0,n.createNewCollection)({models:b.map(function(e){return(0,n.createNewModel)({id:e[l],attributes:e})}),metaData:p}));case e+".INDEX_ERROR":var y=i.error;return a({},r,(0,n.createNewCollection)({metaData:{loading:!1,loadingError:y}}));case e+".SHOW":var g=(i.data||{}).id;return u?(0,n.createNewModel)({metaData:{loading:!0,queryParams:f},attributes:r.attributes}):a({},r,{models:(0,n.setMemberLoading)({id:g,state:r,queryParams:f})});case e+".SHOW_SUCCESS":var E=i.id,I=i.response,A=i.metaData,h=I;return u?(0,n.createNewModel)({id:E,metaData:A,attributes:a({},r.attributes,h)}):a({},r,(0,n.createNewCollection)({models:(0,n.setMemberAttributes)({id:E,data:h,state:r,metaData:a({loading:!1},A)})}));case e+".SHOW_ERROR":var M=i.id,S=i.error;return u?(0,n.createNewModel)({id:M,attributes:a({},r.attributes),metaData:{loadingError:S}}):a({},r,{models:(0,n.setMemberLoadingError)({state:r,id:M,error:S})});case e+".ASSIGN_CID":var D=i.cId;return u?(0,n.createNewModel)({cId:D}):(0,n.createNewCollection)({models:(0,n.setMemberAttributes)({cId:D,state:r})});case e+".CREATE_SUCCESS":var O=i.cId,_=i.id,T=i.response,C=i.metaData,P=T;return u?(0,n.createNewModel)({id:_,cId:O,attributes:a({},r.attributes,P),metaData:C}):(0,n.createNewCollection)({models:(0,n.setMemberAttributes)({data:P,state:r,id:_,cId:O,metaData:C})});case e+".CREATE_ERROR":var j=i.id,w=i.cId,N=i.error;return u?(0,n.createNewModel)({id:j,cId:w,metaData:{loadingError:N}}):a({},r,{models:(0,n.setMemberLoadingError)({state:r,id:j,cId:w,error:N})});case e+".UPDATE":var U=(i.data||{}).id,R=r.__prevData;return u?(0,n.createNewModel)({id:U,metaData:{loading:!0,__prevData:R},attributes:r.attributes}):a({},r,{models:(0,n.setMemberLoading)({id:U,state:r})});case e+".UPDATE_SUCCESS":var q=i.id,x=i.metaData,L=i.response;return u?(0,n.createNewModel)({id:q,attributes:a({},r.attributes,L),metaData:x}):a({},r,{models:(0,n.setMemberAttributes)({id:q,data:L,metaData:x,state:r,replaceAttributes:!1})});case e+".UPDATE_ERROR":var k=i.id,W=i.error;return u?(0,n.createNewModel)({id:k,attributes:r.attributes,metaData:{loadingError:W}}):a({},r,{models:(0,n.setMemberLoadingError)({state:r,id:k,error:W})});case e+".DESTROY":var G=(i.data||{}).id||r.id;return u?(0,n.createNewModel)({id:G,attributes:r.attributes,metaData:{loading:!0}}):a({},r,{models:(0,n.setMemberLoading)({idAttribute:l,id:G,state:r})});case e+".DESTROY_SUCCESS":var X=i.id;return u?null:a({},r,{models:(0,n.destroyMember)({idAttribute:l,id:X,state:r})});case e+".DESTROY_ERROR":var H=i.id,Y=i.error;return a({},r,u?{loading:!1,loadingError:Y}:{models:(0,n.setMemberLoadingError)({state:r,id:H,idAttribute:l,error:Y})});case e+".SET_LOADING":var B=i.id,F=i.cId;return a({},r,u?{loading:!0,loadingError:void 0}:{models:(0,n.setMemberLoading)({idAttribute:l,id:B,cId:F,state:r})});case e+".SET_OPTIMISTIC_DATA":var Q=function(){var e,t=i.id,o=i.cId,c=i.data,d=u?r:(0,n.findModel)({id:t,cId:o,state:r}),s=a({},d.attributes),l={};return Object.keys(n.apiDefaultState).forEach(function(e){l[e]=d[e]}),e=a({},l,{__prevData:s}),u?{v:(0,n.createNewModel)({id:t,cId:o,attributes:a({},d.attributes,c),metaData:e})}:{v:(0,n.createNewCollection)({models:(0,n.setMemberAttributes)({data:c,state:r,id:t,cId:o,metaData:e})})}}();if("object"===(void 0===Q?"undefined":o(Q)))return Q.v;case e+".UNSET_OPTIMISTIC_DATA":var J=i.id,z=i.cId,K=i.destroy,V=u?r:(0,n.findModel)({id:J,cId:z,state:r});return K&&u?null:K?a({},r,{models:(0,n.destroyTempMemeber)({cId:z,state:r})}):u?(0,n.createNewModel)({id:J,cId:z,attributes:V.__prevData}):(0,n.createNewCollection)({models:(0,n.setMemberAttributes)({data:V.__prevData,state:r,id:J,cId:z})});default:var Z=t.resources[e];return Z&&Z.reducer?Z.reducer(r,i):r}}}),(0,i.combineReducers)(r)}},function(t,r){t.exports=e},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.getInitialState=t.setMemberLoadingError=t.setMemberLoading=t.destroyTempMemeber=t.destroyMember=t.setMemberAttributes=t.collectionWithUpdatedModel=t.collectionWithNewModel=t.createNewCollection=t.createNewModel=t.findModel=t.apiDefaultState=void 0;var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},a=r(0);var i=t.apiDefaultState={loading:!1,loadingError:void 0,__prevData:void 0},n=t.findModel=function(e){var t=e.id,r=e.cId,o=e.state,a=o.models&&o.models.slice(0)||[],i=void 0,n=void 0;return a.find(function(e){return i=void 0!==e.id,n=void 0!==r,i&&e.id===t||n&&e.cId===r})},c=t.createNewModel=function(e){var t=e.id,r=e.cId,a=e.metaData,n=e.attributes,c={id:t,cId:r,attributes:o({},void 0===n?{}:n)};return Object.keys(c).forEach(function(e){return void 0===c[e]?delete c[e]:""}),o({},i,a,c)},d=t.createNewCollection=function(e){var t=e.metaData,r=e.models;return o({},i,t,{models:void 0===r?[]:r})},s=t.collectionWithNewModel=function(e){var t=e.state,r=e.model,o=t.models||[];return[].concat(function(e){if(Array.isArray(e)){for(var t=0,r=Array(e.length);t<e.length;t++)r[t]=e[t];return r}return Array.from(e)}(o),[r])},u=t.collectionWithUpdatedModel=function(e){var t=e.id,r=e.cId,o=e.state,a=e.updatedModel,i=o.models&&o.models.slice(0)||[],n=void 0,c=void 0;return i.map(function(e){return n=void 0!==e.id,c=void 0!==r,n&&e.id===t||c&&e.cId===r?a:e})},l=t.setMemberAttributes=function(e){var t,r=e.id,a=e.data,i=e.metaData,d=e.state,l=e.cId,f=e.replaceAttributes,m=void 0===f||f,b=(e.replaceMeta,n({id:r,cId:l,state:d}));return b?(t=m?a:o({},b.attributes,a),!l&&b.cId&&(l=b.cId),u({id:r,cId:l,state:d,updatedModel:c({id:r,cId:l,metaData:i,attributes:t})})):s({state:d,model:c({id:r,cId:l,metaData:i,attributes:a})})},f=t.destroyMember=function(e){var t=e.id;return e.state.models.filter(function(e){return e.id!==t})},m=t.destroyTempMemeber=function(e){var t=e.cId;return e.state.models.filter(function(e){return e.cId!==t})},b=t.setMemberLoading=function(e){var t=e.id,r=e.cId,o=e.state,a=e.queryParams,i=n({id:t,cId:r,state:o});return i?u({id:t,cId:r,state:o,updatedModel:c({id:t,cId:r,metaData:{loading:!0,queryParams:a},attributes:i.attributes})}):s({state:o,model:c({id:t,cId:r,metaData:{loading:!0,queryParams:a}})})},p=t.setMemberLoadingError=function(e){var t=e.id,r=e.cId,a=e.state,i=e.error,d=n({id:t,cId:r,state:a});return d||t?d?u({id:t,state:a,cId:r,updatedModel:c(o({},d,{metaData:{loadingError:i,__prevData:d.__prevData}}))}):s({state:a,model:c({id:t,metaData:{loadingError:i}})}):a.models.slice(0)},v=t.getInitialState=function(e){var t=e.config,r=e.resource,o=(0,a.getResourceNameSpace)({config:t,resource:r}),i="attributes"===o,n=t.resources[r]||{},s=(0,a.getResourceIdAttribute)({config:t,resource:r}),u=void 0;return i?(u=n[o]?n[s]||n.attributes[s]:void 0,c({id:u,idAttribute:s,attributes:n.attributes})):d({models:(n.models||[]).map(function(e){return c({idAttribute:s,id:e[s],attributes:e})})})};t.default={apiDefaultState:i,findModel:n,createNewModel:c,createNewCollection:d,collectionWithNewModel:s,collectionWithUpdatedModel:u,setMemberAttributes:l,destroyMember:f,destroyTempMemeber:m,setMemberLoading:b,setMemberLoadingError:p,getInitialState:v}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e},a=t.index=function(e){var t=e.resource,r=e.controller;return{type:t+".INDEX",data:{queryParams:e.queryParams},controller:r}},i=t.show=function(e){var t=e.id,r=e.resource,o=e.controller;return{type:r+".SHOW",data:{id:t,queryParams:e.queryParams},controller:o}},n=t.update=function(e){var t=e.id,r=e.attributes,a=e.resource,i=e.controller;return{type:a+".UPDATE",data:o({id:t},r),controller:i}},c=t.create=function(e){return{type:e.resource+".CREATE",data:e.attributes,controller:e.controller}},d=t.destroy=function(e){var t=e.id;return{type:e.resource+".DESTROY",data:{id:t},controller:e.controller}};t.default={index:a,show:i,update:n,create:c,destroy:d}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=r(0);t.default=function(){for(var e=arguments.length,t=Array(e),r=0;r<e;r++)t[r]=arguments[r];var a=(0,o.getConfig)({config:t[0]})||{},i=Object.assign({},a,{resources:Object.assign({},a.resources)});return t.map(function(e){var t=(0,o.getConfig)({config:e});if(t.resources){var r={};return Object.keys(t.resources||{}).forEach(function(e){var i=t.resources[e];"baseUrl"===e&&"string"==typeof i||"optimisticUpdateEnabled"===e&&(0,o.isBool)(i)||(r[e]=Object.assign({},i,{baseUrl:i.baseUrl||t.resources.baseUrl||a.baseUrl,optimisticUpdateEnabled:(0,o.determinOptimisticUpdateSetting)({resourceConfig:i,config:t,defaultConfig:a})}))}),r}}).filter(function(e){return void 0!==e}).forEach(function(e){Object.keys(e).forEach(function(t){var r=e[t];i.resources[t]=Object.assign({},r)})}),i}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("redux")):"function"==typeof define&&define.amd?define(["redux"],t):"object"==typeof exports?exports["redux-rails"]=t(require("redux")):e["redux-rails"]=t(e.redux)}("undefined"!=typeof self?self:this,(function(e){return function(e){var t={};function r(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=t,r.d=function(e,t,a){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(r.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(a,o,function(t){return e[t]}.bind(null,o));return a},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1)}([function(t,r){t.exports=e},function(e,t,r){"use strict";r.r(t);let a=0;const o=({resourceConfig:e,config:t,defaultConfig:r={}})=>d(e.optimisticUpdateEnabled)?e.optimisticUpdateEnabled:d(t.resources.optimisticUpdateEnabled)?t.resources.optimisticUpdateEnabled:d(t.optimisticUpdateEnabled)?t.optimisticUpdateEnabled:!d(r.optimisticUpdateEnabled)||r.optimisticUpdateEnabled,s=({controller:e})=>"s"===e[e.length-1]?"collection":"member",i=({config:e,resource:t})=>{const r=e.resources[t].controller;return"collection"===s({controller:r})?"models":"attributes"},c=({config:e,resource:t})=>e.resources[t].idAttribute||"id",d=e=>"boolean"==typeof e,n=({config:e,store:t})=>"function"==typeof e?e(t):e;let u={};const l={SHOW:"GET",INDEX:"GET",CREATE:"POST",UPDATE:"PUT",DESTROY:"DELETE"},m=(e,t)=>`${e}=${encodeURIComponent(t)}`,f=(e,t)=>Array.isArray(t)?((e,t)=>t.map(t=>m(`${e}[]`,t)))(e,t):m(e,t),p=({baseUrl:e,controller:t,railsAction:r,data:a,queryParams:o={}})=>{const i=s({controller:t}),c=(e=>e.includes("/:id/"))(t),d=()=>c||"collection"===i&&"INDEX"!==r&&"CREATE"!==r?`/${a.id}`:"",n=((e={},t)=>{const r=Object.keys(e).filter(t=>void 0!==e[t]||null!==e[t]);return 0===r.length||"GET"!==l[t]?"":`?${r.map(t=>f(t,e[t])).join("&")}`})(o,r);let u;return u=c?`${e}${t}`.replace("/:id",d()):`${e}${t}${d()}`,`${u}${n}`},b=({store:e,resource:t,railsAction:r,error:a,id:o,cId:s,optimisticUpdateEnabled:i,reject:c})=>{const d={type:`${t}.${r}_ERROR`,error:a,id:o,cId:s},n="CREATE"===r;e.dispatch(d),["CREATE","UPDATE"].includes(r)&&i&&e.dispatch({type:`${t}.UNSET_OPTIMISTIC_DATA`,id:o,cId:s,destroy:n}),c(d)},E=({store:e,resource:t,config:r,data:i={},railsAction:d,controllerOverride:n,fetchParamsOverride:u,queryParamsOverride:m,resolve:f,reject:y})=>{const D=r.resources[t],A=D.baseUrl||r.baseUrl,h=n||D.controller,S=c({config:r,resource:t}),T=u||D.fetchParams||r.fetchParams,O=m||D.queryParams||r.queryParams,_=(({railsAction:e,resource:t,config:r,data:a,fetchParams:o={}})=>{const s=l[e],i=new Headers(o.headers||{});let c=Object.assign({},o,{method:s,headers:i});return"object"==typeof a&&"GET"!==s&&(c.body=JSON.stringify(a)),c})({railsAction:d,resource:t,data:i,config:r,fetchParams:T}),P=p({baseUrl:A,controller:h,railsAction:d,data:i,fetchParams:T,queryParams:O}),v=o({resourceConfig:D,config:r});let $;"CREATE"===d&&($=++a,e.dispatch({type:`${t}.ASSIGN_CID`,cId:$}),e.dispatch({type:`${t}.SET_LOADING`,cId:$})),["CREATE","UPDATE"].includes(d)&&v&&e.dispatch({type:`${t}.SET_OPTIMISTIC_DATA`,id:i.id,cId:$,data:i}),fetch(P,_).then(a=>{a.json().then(o=>{const c=o&&o[S]||i.id;if(!a.ok)return b({store:e,resource:t,railsAction:d,id:c,cId:$,optimisticUpdateEnabled:v,reject:y,error:o.error||{message:a.statusText}});(({store:e,resource:t,railsAction:r,id:a,cId:o,json:i,config:c,controller:d,resolve:n})=>{const u=`${t}.${r}_SUCCESS`,{response:l,metaData:m}=I({json:i,resource:t,config:c,resourceType:s({controller:d})}),f={cId:o,id:a,metaData:m,response:l,type:u};e.dispatch(f),n(f)})({store:e,resource:t,railsAction:d,id:c,cId:$,json:o,config:r,controller:h,optimisticUpdateEnabled:v,resolve:f})}).catch(r=>{const a=r&&r.toString&&r.toString();b({store:e,resource:t,railsAction:d,error:a,id:i.id,cId:$,optimisticUpdateEnabled:v,reject:y})})}).catch(r=>{b({store:e,resource:t,railsAction:d,error:r,id:i.id,cId:$,optimisticUpdateEnabled:v,reject:y})}).then(()=>(({resource:e})=>{const t=g({resource:e});t.shift(),t.length>0&&E(t[0])})({resource:t}))},g=({resource:e})=>(u[e]||(u[e]={queue:[]}),u[e].queue),I=({json:e,resource:t,config:r,resourceType:a})=>{const o=r.resources[t].parse,s=r.resources[t].setMetadata;let i,c={};switch(typeof o){case"object":{const t=o&&o[a];if(!t){i=e;break}i=t(e);break}case"function":i=o(e);break;default:i=e}switch(typeof s){case"object":{const t=s&&s[a];if(!t)break;c=t(e);break}case"function":c=s(e);break;default:c={}}return{response:i,metaData:c}},y=({action:e,config:t,fetchData:r,next:a,resource:o,resourceConfig:s})=>{const i=new Promise((e,a)=>{const i={resolve:e,reject:a,...r};(t.disableFetchQueueing||s.disableFetchQueueing)&&E(i),((e,t)=>{const r=g({resource:e});r.push(t),r.length<=1&&E(t)})(o,i)});return a(e),i};var D=e=>t=>r=>a=>{const o=n({config:e,store:t.getState()}),[s,i]=a.type.split("."),{data:c,controller:d,fetchParams:u}=a,{queryParams:m}=c||{},f={store:t,resource:s,config:o,data:c,railsAction:i,controllerOverride:d,fetchParamsOverride:u,queryParamsOverride:m},p=o.resources[s];return p&&l[i]?y({action:a,config:o,fetchData:f,next:r,resource:s,resourceConfig:p}):r(a)},A=r(0);const h={loading:!1,loadingError:void 0,__prevData:void 0},S=({id:e,cId:t,state:r})=>{let a,o;return(r.models&&r.models.slice(0)||[]).find(r=>(a=void 0!==r.id,o=void 0!==t,a&&r.id===e||o&&r.cId===t))},T=({id:e,cId:t,metaData:r,attributes:a={}})=>{let o={id:e,cId:t,attributes:{...a}};return Object.keys(o).forEach(e=>void 0===o[e]?delete o[e]:""),{...h,...r,...o}},O=({metaData:e,models:t=[]})=>({...h,...e,models:t}),_=({state:e,model:t})=>[...e.models||[],t],P=({id:e,cId:t,state:r,updatedModel:a})=>{let o,s;return(r.models&&r.models.slice(0)||[]).map(r=>(o=void 0!==r.id,s=void 0!==t,o&&r.id===e||s&&r.cId===t?a:r))},v=({id:e,data:t,metaData:r,state:a,cId:o,replaceAttributes:s=!0,replaceMeta:i=!0})=>{const c=S({id:e,cId:o,state:a});let d;return c?(d=s?t:{...c.attributes,...t},!o&&c.cId&&(o=c.cId),P({id:e,cId:o,state:a,updatedModel:T({id:e,cId:o,metaData:r,attributes:d})})):_({state:a,model:T({id:e,cId:o,metaData:r,attributes:t})})},$=({id:e,state:t})=>t.models.filter(t=>t.id!==e),U=({cId:e,state:t})=>t.models.filter(t=>t.cId!==e),j=({id:e,cId:t,state:r,queryParams:a})=>{const o=S({id:e,cId:t,state:r});return o?P({id:e,cId:t,state:r,updatedModel:T({id:e,cId:t,metaData:{loading:!0,queryParams:a},attributes:o.attributes})}):_({state:r,model:T({id:e,cId:t,metaData:{loading:!0,queryParams:a}})})},C=({id:e,cId:t,state:r,error:a})=>{const o=S({id:e,cId:t,state:r});return o||e?o?P({id:e,state:r,cId:t,updatedModel:T({...o,metaData:{loadingError:a,__prevData:o.__prevData}})}):_({state:r,model:T({id:e,metaData:{loadingError:a}})}):r.models.slice(0)},R=({config:e,resource:t})=>{const r=i({config:e,resource:t}),a="attributes"===r,o=e.resources[t]||{},s=c({config:e,resource:t});let d;return a?(d=o[r]?o[s]||o.attributes[s]:void 0,T({id:d,idAttribute:s,attributes:o.attributes})):O({models:(o.models||[]).map(e=>T({idAttribute:s,id:e[s],attributes:e}))})};var q=e=>{const t=n({config:e}),r={};return Object.keys(t.resources).forEach(e=>{r[e]=(r=R({config:t,resource:e}),a={})=>{const o=t.resources[e]||{},s="attributes"===i({config:t,resource:e}),d=c({config:t,resource:e}),{queryParams:n}=a.data||{};switch(a.type){case`${e}.INDEX`:{const{paginated:e}=o;return{...r,...O({metaData:{loading:!0,queryParams:n},models:e?r.models:[]})}}case`${e}.INDEX_SUCCESS`:{let{response:t,metaData:s}=a;const i=a.response[e]||a.response[e.toLowerCase()];if(!Array.isArray(a.response)){if(!i||!Array.isArray(i))return console.error("Response to INDEX actions must be of type array OR contain a top-level key matching the resource name with an array as the value. You can use the parse method(s) set in your config for this resource to transform returned data if needed."),{...r,...O({metaData:{loading:!1,loadingError:"Bad data received from server. INDEX calls expect an array."}})};t=i}if(o.paginated){const e=t.reduce((e,t)=>({...e,[t.id]:t}),{}),a=r.models.map(e=>e.attributes),o={};t=[...a.map(t=>e[t.id]?(o[t.id]=!0,e[t.id]):t),...t.filter(e=>!o[e.id])]}return{...r,...O({models:t.map(e=>T({id:e[d],attributes:e})),metaData:s})}}case`${e}.INDEX_ERROR`:{const{error:e}=a;return{...r,...O({metaData:{loading:!1,loadingError:e}})}}case`${e}.SHOW`:{const e=a.data||{},{id:t}=e;return s?T({metaData:{loading:!0,queryParams:n},attributes:r.attributes}):{...r,models:j({id:t,state:r,queryParams:n})}}case`${e}.SHOW_SUCCESS`:{const{id:e,response:t,metaData:o}=a,i=t;return s?T({id:e,metaData:o,attributes:{...r.attributes,...i}}):{...r,...O({models:v({id:e,data:i,state:r,metaData:{loading:!1,...o}})})}}case`${e}.SHOW_ERROR`:{const{id:e,error:t}=a;return s?T({id:e,attributes:{...r.attributes},metaData:{loadingError:t}}):{...r,models:C({state:r,id:e,error:t})}}case`${e}.ASSIGN_CID`:{const{cId:e}=a;return s?T({cId:e}):O({models:v({cId:e,state:r})})}case`${e}.CREATE_SUCCESS`:{const{cId:e,id:t,response:o,metaData:i}=a,c=o;return s?T({id:t,cId:e,attributes:{...r.attributes,...c},metaData:i}):O({models:v({data:c,state:r,id:t,cId:e,metaData:i})})}case`${e}.CREATE_ERROR`:{const{id:e,cId:t,error:o}=a;return s?T({id:e,cId:t,metaData:{loadingError:o}}):{...r,models:C({state:r,id:e,cId:t,error:o})}}case`${e}.UPDATE`:{const e=a.data||{},{id:t}=e,o=r.__prevData;return s?T({id:t,metaData:{loading:!0,__prevData:o},attributes:r.attributes}):{...r,models:j({id:t,state:r})}}case`${e}.UPDATE_SUCCESS`:{const{id:e,metaData:t,response:o}=a,i=o;return s?T({id:e,attributes:{...r.attributes,...i},metaData:t}):{...r,models:v({id:e,data:i,metaData:t,state:r,replaceAttributes:!1})}}case`${e}.UPDATE_ERROR`:{const{id:e,error:t}=a;return s?T({id:e,attributes:r.attributes,metaData:{loadingError:t}}):{...r,models:C({state:r,id:e,error:t})}}case`${e}.DESTROY`:{const e=(a.data||{}).id||r.id;return s?T({id:e,attributes:r.attributes,metaData:{loading:!0}}):{...r,models:j({idAttribute:d,id:e,state:r})}}case`${e}.DESTROY_SUCCESS`:{const{id:e}=a;return s?null:{...r,models:$({idAttribute:d,id:e,state:r})}}case`${e}.DESTROY_ERROR`:{const{id:e,error:t}=a;return s?{...r,loading:!1,loadingError:t}:{...r,models:C({state:r,id:e,idAttribute:d,error:t})}}case`${e}.SET_LOADING`:{const{id:e,cId:t}=a;return s?{...r,loading:!0,loadingError:void 0}:{...r,models:j({idAttribute:d,id:e,cId:t,state:r})}}case`${e}.SET_OPTIMISTIC_DATA`:{const{id:e,cId:t,data:o}=a,i=s?r:S({id:e,cId:t,state:r}),c={...i.attributes};let d,n={};return Object.keys(h).forEach(e=>{n[e]=i[e]}),d={...n,__prevData:c},s?T({id:e,cId:t,attributes:{...i.attributes,...o},metaData:d}):O({models:v({data:o,state:r,id:e,cId:t,metaData:d})})}case`${e}.UNSET_OPTIMISTIC_DATA`:{const{id:e,cId:t,destroy:o}=a,i=s?r:S({id:e,cId:t,state:r});return o&&s?null:o?{...r,models:U({cId:t,state:r})}:s?T({id:e,cId:t,attributes:i.__prevData}):O({models:v({data:i.__prevData,state:r,id:e,cId:t})})}default:{const o=t.resources[e];return o&&o.reducer?o.reducer(r,a):r}}}}),Object(A.combineReducers)(r)};var x={index:({resource:e,controller:t,queryParams:r})=>({type:`${e}.INDEX`,data:{queryParams:r},controller:t}),show:({id:e,resource:t,controller:r,queryParams:a})=>({type:`${t}.SHOW`,data:{id:e,queryParams:a},controller:r}),update:({id:e,attributes:t,resource:r,controller:a})=>({type:`${r}.UPDATE`,data:{id:e,...t},controller:a}),create:({resource:e,attributes:t,controller:r})=>({type:`${e}.CREATE`,data:t,controller:r}),destroy:({id:e,resource:t,controller:r})=>({type:`${t}.DESTROY`,data:{id:e},controller:r})},N=(...e)=>{const t=n({config:e[0]})||{};let r=Object.assign({},t,{resources:Object.assign({},t.resources)});return e.map(e=>{const r=n({config:e});if(!r.resources)return;const a={};return Object.keys(r.resources||{}).forEach(e=>{const s=r.resources[e];"baseUrl"===e&&"string"==typeof s||"optimisticUpdateEnabled"===e&&d(s)||(a[e]=Object.assign({},s,{baseUrl:s.baseUrl||r.resources.baseUrl||t.baseUrl,optimisticUpdateEnabled:o({resourceConfig:s,config:r,defaultConfig:t})}))}),a}).filter(e=>void 0!==e).forEach(e=>{Object.keys(e).forEach(t=>{let a=e[t];r.resources[t]=Object.assign({},a)})}),r};r.d(t,"apiReducer",(function(){return q})),r.d(t,"combineConfigs",(function(){return N})),r.d(t,"middleWare",(function(){return D})),r.d(t,"railsActions",(function(){return x}))}])})); |
{ | ||
"name": "redux-rails", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Redux and your server talking without fuss.", | ||
@@ -30,17 +30,15 @@ "main": "dist/redux-rails.js", | ||
"devDependencies": { | ||
"babel-core": "^6.21.0", | ||
"babel-jest": "^18.0.0", | ||
"babel-loader": "^7.1.5", | ||
"@babel/core": "^7.4.5", | ||
"@babel/preset-env": "^7.4.5", | ||
"babel-jest": "^24.8.0", | ||
"babel-loader": "^8.0.6", | ||
"babel-polyfill": "^6.22.0", | ||
"babel-preset-es2015": "^6.18.0", | ||
"babel-preset-react": "^6.16.0", | ||
"babel-preset-stage-3": "^6.17.0", | ||
"es6-promise": "^4.0.5", | ||
"isomorphic-fetch": "^2.2.1", | ||
"jest": "^22.4.2", | ||
"nock": "^9.0.2", | ||
"jest": "^24.8.0", | ||
"nock": "9.0.6", | ||
"path": "^0.12.7", | ||
"redux": ">=3.6.0", | ||
"webpack": "^4.16.5", | ||
"webpack-bundle-analyzer": "^2.13.1", | ||
"redux": "^4.0.4", | ||
"webpack": "^4.41.2", | ||
"webpack-bundle-analyzer": "^3.3.2", | ||
"webpack-cli": "^3.1.0" | ||
@@ -47,0 +45,0 @@ }, |
@@ -5,3 +5,3 @@ Redux Rails | ||
[![CircleCI](https://circleci.com/gh/instacart/redux-rails.svg?style=shield&circle-token=dfe00f3d2f89c4b810250f6d18b384df3ab1bc6b)](https://circleci.com/gh/instacart/redux-rails) | ||
[![npm](https://img.shields.io/npm/v/redux-rails.svg?style=flat-square)](https://www.npmjs.com/package/redux-rails) [![license](https://img.shields.io/npm/l/redux-rails.svg?style=flat-square)](https://github.com/instacart/redux-rails/blob/master/LICENSE) [![CircleCI](https://circleci.com/gh/instacart/redux-rails.svg?style=shield&circle-token=dfe00f3d2f89c4b810250f6d18b384df3ab1bc6b)](https://circleci.com/gh/instacart/redux-rails) [![Maintainability](https://api.codeclimate.com/v1/badges/577b533d91a0f56fa728/maintainability)](https://codeclimate.com/github/instacart/redux-rails/maintainability) | ||
@@ -8,0 +8,0 @@ Redux Rails is a Redux middleware for auto-generating the actions, reducers and settings for talking to your RESTful backend. It removes boilerplate and keeps your app consistent. |
@@ -32,3 +32,3 @@ import { combineReducers } from 'redux' | ||
const { queryParams } = action.data || {} | ||
switch(action.type) { | ||
@@ -77,6 +77,18 @@ case `${resource}.INDEX`: { | ||
// prefer response's model data over existing model data | ||
const newResponseIds = response.reduce((memo, r) => ({ ...memo, [r.id]: true }), {}) | ||
// maintain order of existing data if response includes some of the same data | ||
const newResponseIdMap = response.reduce((memo, r) => ({ ...memo, [r.id]: r }), {}) | ||
const existingData = state.models.map(m => m.attributes) | ||
const updatedDataIds = {} | ||
const updatedExistingData = existingData.map(m => { | ||
if (newResponseIdMap[m.id]) { | ||
updatedDataIds[m.id] = true | ||
return newResponseIdMap[m.id] | ||
} | ||
return m | ||
}) | ||
response = [ | ||
...state.models.map(m => m.attributes).filter(m => !newResponseIds[m.id]), | ||
...response | ||
...updatedExistingData, | ||
...response.filter(r => !updatedDataIds[r.id]) | ||
] | ||
@@ -83,0 +95,0 @@ } |
import apiReducer from '../../src/apiReducer' | ||
import railsActions from '../../src/railsActions' | ||
import { standardConfig } from './exampleConfigs' | ||
import { standardConfig, configWithMetaDataSetting } from './exampleConfigs' | ||
describe('INDEX actions', () => { | ||
const indexReducer = apiReducer(standardConfig) | ||
const indexReducerWithPaginate = apiReducer(configWithMetaDataSetting) | ||
let indexReducerState = {} | ||
@@ -29,2 +30,14 @@ const baseModelState = { | ||
const baseCatsExpectedState = { | ||
Cats: baseCollectionState, | ||
} | ||
const expectedCatsState = (newState) => ({ | ||
...baseCatsExpectedState, | ||
Cats: { | ||
...baseCollectionState, | ||
...newState | ||
} | ||
}) | ||
it('should set queryParams on the collection', () => { | ||
@@ -134,2 +147,78 @@ const queryParams = { foo: 'bar' } | ||
}) | ||
describe('pagination', () => { | ||
it('should work correctly when there are no overrides', () => { | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 1, foo: 'bar1'}, {id: 2, foo: 'bar2'}, {id: 3, foo: 'bar3'}]} | ||
}) | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 4, foo: 'bar4'}, {id: 5, foo: 'bar5'}, {id: 6, foo: 'bar6'}]} | ||
}) | ||
expect(indexReducerState).toEqual(expectedCatsState({ | ||
models: [ | ||
{loading: false, loadingError: undefined, id: 1, attributes: {id: 1, foo: 'bar1'}}, | ||
{loading: false, loadingError: undefined, id: 2, attributes: {id: 2, foo: 'bar2'}}, | ||
{loading: false, loadingError: undefined, id: 3, attributes: {id: 3, foo: 'bar3'}}, | ||
{loading: false, loadingError: undefined, id: 4, attributes: {id: 4, foo: 'bar4'}}, | ||
{loading: false, loadingError: undefined, id: 5, attributes: {id: 5, foo: 'bar5'}}, | ||
{loading: false, loadingError: undefined, id: 6, attributes: {id: 6, foo: 'bar6'}}, | ||
] | ||
})) | ||
}) | ||
it('should keep overridden data in the same order', () => { | ||
indexReducerState = indexReducerWithPaginate({}, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 1, foo: 'bar1'}, {id: 2, foo: 'bar2'}, {id: 3, foo: 'bar3'}]} | ||
}) | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 4, foo: 'bar4'}, {id: 5, foo: 'bar5'}, {id: 6, foo: 'bar6'}]} | ||
}) | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 7, foo: 'bar7'}, {id: 2, foo: 'changedBar2'}, {id: 8, foo: 'bar8'}]} | ||
}) | ||
expect(indexReducerState).toEqual(expectedCatsState({ | ||
models: [ | ||
{loading: false, loadingError: undefined, id: 1, attributes: {id: 1, foo: 'bar1'}}, | ||
{loading: false, loadingError: undefined, id: 2, attributes: {id: 2, foo: 'changedBar2'}}, | ||
{loading: false, loadingError: undefined, id: 3, attributes: {id: 3, foo: 'bar3'}}, | ||
{loading: false, loadingError: undefined, id: 4, attributes: {id: 4, foo: 'bar4'}}, | ||
{loading: false, loadingError: undefined, id: 5, attributes: {id: 5, foo: 'bar5'}}, | ||
{loading: false, loadingError: undefined, id: 6, attributes: {id: 6, foo: 'bar6'}}, | ||
{loading: false, loadingError: undefined, id: 7, attributes: {id: 7, foo: 'bar7'}}, | ||
{loading: false, loadingError: undefined, id: 8, attributes: {id: 8, foo: 'bar8'}}, | ||
] | ||
})) | ||
}) | ||
it(`should keep not re-arrange data that's passed in a different order than originally`, () => { | ||
indexReducerState = indexReducerWithPaginate({}, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 1, foo: 'bar1'}, {id: 2, foo: 'bar2'}, {id: 3, foo: 'bar3'}]} | ||
}) | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 2, foo: 'changedbar2'}, {id: 1, foo: 'changedbar1'}, {id: 3, foo: 'changedbar3'}]} | ||
}) | ||
indexReducerState = indexReducerWithPaginate(indexReducerState, { | ||
type: 'Cats.INDEX_SUCCESS', | ||
response: {Cats: [{id: 5, foo: 'bar5'}]} | ||
}) | ||
expect(indexReducerState).toEqual(expectedCatsState({ | ||
models: [ | ||
{loading: false, loadingError: undefined, id: 1, attributes: {id: 1, foo: 'changedbar1'}}, | ||
{loading: false, loadingError: undefined, id: 2, attributes: {id: 2, foo: 'changedbar2'}}, | ||
{loading: false, loadingError: undefined, id: 3, attributes: {id: 3, foo: 'changedbar3'}}, | ||
{loading: false, loadingError: undefined, id: 5, attributes: {id: 5, foo: 'bar5'}}, | ||
] | ||
})) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
14
6754
711200
36
3