strange-middle-end
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -12,36 +12,14 @@ 'use strict'; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
return _typeof(obj); | ||
} | ||
@@ -123,2 +101,6 @@ | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -263,2 +245,17 @@ var _n = true; | ||
}); | ||
initializedProp('select', function () { | ||
var selectors = middleEnd.selectors, | ||
getState = middleEnd.getState; // Convenient selection, | ||
// select.auth.isAuthenticated() versus selectors.auth.isAuthenticated(getState()) | ||
return internals.mapEachLeafFunction(selectors, function (selector) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return selector.apply(void 0, [getState()].concat(args)); | ||
}; | ||
}); | ||
}); | ||
initializedProp('selectors', function () { | ||
@@ -319,2 +316,12 @@ return internals.pickEach(middleEnd.mods, 'selectors'); | ||
internals.mapEachLeafFunction = function (obj, map) { | ||
return Object.entries(obj).reduce(function (collect, _ref11) { | ||
var _ref12 = _slicedToArray(_ref11, 2), | ||
key = _ref12[0], | ||
value = _ref12[1]; | ||
return _objectSpread2({}, collect, _defineProperty({}, key, typeof value === 'function' ? map(value) : value && _typeof(value) === 'object' ? internals.mapEachLeafFunction(value, map) : value)); | ||
}, {}); | ||
}; | ||
var internals$1 = {}; | ||
@@ -373,96 +380,85 @@ | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(dispatch) { | ||
var beginPayload, computedArgs, index, successPayload, error; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
beginPayload = transform.apply(void 0, args); | ||
computedArgs = [].concat(beginPayload); | ||
return function _callee(dispatch) { | ||
var beginPayload, computedArgs, index, successPayload, error; | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
beginPayload = transform.apply(void 0, args); | ||
computedArgs = [].concat(beginPayload); | ||
index = function () { | ||
if (!indexed) { | ||
return null; | ||
} | ||
index = function () { | ||
if (!indexed) { | ||
return null; | ||
} | ||
if (typeof indexed === 'string') { | ||
return indexed; | ||
} | ||
if (typeof indexed === 'string') { | ||
return indexed; | ||
} | ||
if (typeof indexed === 'function') { | ||
return indexed.apply(void 0, _toConsumableArray(computedArgs)); | ||
} | ||
if (typeof indexed === 'function') { | ||
return indexed.apply(void 0, _toConsumableArray(computedArgs)); | ||
} | ||
return actionTypes.BASE; | ||
}(); | ||
return actionTypes.BASE; | ||
}(); | ||
_context.prev = 3; | ||
dispatch({ | ||
type: actionTypes.BEGIN, | ||
payload: beginPayload, | ||
meta: { | ||
index: index | ||
} | ||
}); | ||
_context.next = 7; | ||
return handler.apply(void 0, _toConsumableArray(computedArgs)); | ||
_context.prev = 3; | ||
dispatch({ | ||
type: actionTypes.BEGIN, | ||
payload: beginPayload, | ||
meta: { | ||
index: index | ||
} | ||
}); | ||
_context.next = 7; | ||
return regeneratorRuntime.awrap(handler.apply(void 0, _toConsumableArray(computedArgs))); | ||
case 7: | ||
successPayload = _context.sent; | ||
case 7: | ||
successPayload = _context.sent; | ||
if (schema) { | ||
successPayload = Normalizr.normalize(successPayload, schema); | ||
} | ||
if (schema) { | ||
successPayload = Normalizr.normalize(successPayload, schema); | ||
} | ||
dispatch({ | ||
type: actionTypes.SUCCESS, | ||
payload: successPayload, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); // after will possibly fire async | ||
dispatch({ | ||
type: actionTypes.SUCCESS, | ||
payload: successPayload, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); // after will possibly fire async | ||
if (after) { | ||
after({ | ||
original: beginPayload, | ||
result: successPayload | ||
}); | ||
} | ||
if (after) { | ||
after({ | ||
original: beginPayload, | ||
result: successPayload | ||
}); | ||
} | ||
return _context.abrupt("return", [null, successPayload]); | ||
return _context.abrupt("return", [null, successPayload]); | ||
case 14: | ||
_context.prev = 14; | ||
_context.t0 = _context["catch"](3); | ||
error = internals$1.ensureError(_context.t0); | ||
dispatch({ | ||
type: actionTypes.FAIL, | ||
payload: error, | ||
error: true, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); | ||
return _context.abrupt("return", [error]); | ||
case 14: | ||
_context.prev = 14; | ||
_context.t0 = _context["catch"](3); | ||
error = internals$1.ensureError(_context.t0); | ||
dispatch({ | ||
type: actionTypes.FAIL, | ||
payload: error, | ||
error: true, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); | ||
return _context.abrupt("return", [error]); | ||
case 19: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[3, 14]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}() | ||
); | ||
case 19: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, null, null, [[3, 14]]); | ||
}; | ||
}; | ||
@@ -469,0 +465,0 @@ }; |
@@ -6,36 +6,14 @@ import { combineReducers } from 'redux'; | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
return _typeof(obj); | ||
} | ||
@@ -117,2 +95,6 @@ | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -257,2 +239,17 @@ var _n = true; | ||
}); | ||
initializedProp('select', function () { | ||
var selectors = middleEnd.selectors, | ||
getState = middleEnd.getState; // Convenient selection, | ||
// select.auth.isAuthenticated() versus selectors.auth.isAuthenticated(getState()) | ||
return internals.mapEachLeafFunction(selectors, function (selector) { | ||
return function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return selector.apply(void 0, [getState()].concat(args)); | ||
}; | ||
}); | ||
}); | ||
initializedProp('selectors', function () { | ||
@@ -313,2 +310,12 @@ return internals.pickEach(middleEnd.mods, 'selectors'); | ||
internals.mapEachLeafFunction = function (obj, map) { | ||
return Object.entries(obj).reduce(function (collect, _ref11) { | ||
var _ref12 = _slicedToArray(_ref11, 2), | ||
key = _ref12[0], | ||
value = _ref12[1]; | ||
return _objectSpread2({}, collect, _defineProperty({}, key, typeof value === 'function' ? map(value) : value && _typeof(value) === 'object' ? internals.mapEachLeafFunction(value, map) : value)); | ||
}, {}); | ||
}; | ||
var internals$1 = {}; | ||
@@ -367,96 +374,85 @@ | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regeneratorRuntime.mark(function _callee(dispatch) { | ||
var beginPayload, computedArgs, index, successPayload, error; | ||
return regeneratorRuntime.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
beginPayload = transform.apply(void 0, args); | ||
computedArgs = [].concat(beginPayload); | ||
return function _callee(dispatch) { | ||
var beginPayload, computedArgs, index, successPayload, error; | ||
return regeneratorRuntime.async(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
beginPayload = transform.apply(void 0, args); | ||
computedArgs = [].concat(beginPayload); | ||
index = function () { | ||
if (!indexed) { | ||
return null; | ||
} | ||
index = function () { | ||
if (!indexed) { | ||
return null; | ||
} | ||
if (typeof indexed === 'string') { | ||
return indexed; | ||
} | ||
if (typeof indexed === 'string') { | ||
return indexed; | ||
} | ||
if (typeof indexed === 'function') { | ||
return indexed.apply(void 0, _toConsumableArray(computedArgs)); | ||
} | ||
if (typeof indexed === 'function') { | ||
return indexed.apply(void 0, _toConsumableArray(computedArgs)); | ||
} | ||
return actionTypes.BASE; | ||
}(); | ||
return actionTypes.BASE; | ||
}(); | ||
_context.prev = 3; | ||
dispatch({ | ||
type: actionTypes.BEGIN, | ||
payload: beginPayload, | ||
meta: { | ||
index: index | ||
} | ||
}); | ||
_context.next = 7; | ||
return handler.apply(void 0, _toConsumableArray(computedArgs)); | ||
_context.prev = 3; | ||
dispatch({ | ||
type: actionTypes.BEGIN, | ||
payload: beginPayload, | ||
meta: { | ||
index: index | ||
} | ||
}); | ||
_context.next = 7; | ||
return regeneratorRuntime.awrap(handler.apply(void 0, _toConsumableArray(computedArgs))); | ||
case 7: | ||
successPayload = _context.sent; | ||
case 7: | ||
successPayload = _context.sent; | ||
if (schema) { | ||
successPayload = normalize(successPayload, schema); | ||
} | ||
if (schema) { | ||
successPayload = normalize(successPayload, schema); | ||
} | ||
dispatch({ | ||
type: actionTypes.SUCCESS, | ||
payload: successPayload, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); // after will possibly fire async | ||
dispatch({ | ||
type: actionTypes.SUCCESS, | ||
payload: successPayload, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); // after will possibly fire async | ||
if (after) { | ||
after({ | ||
original: beginPayload, | ||
result: successPayload | ||
}); | ||
} | ||
if (after) { | ||
after({ | ||
original: beginPayload, | ||
result: successPayload | ||
}); | ||
} | ||
return _context.abrupt("return", [null, successPayload]); | ||
return _context.abrupt("return", [null, successPayload]); | ||
case 14: | ||
_context.prev = 14; | ||
_context.t0 = _context["catch"](3); | ||
error = internals$1.ensureError(_context.t0); | ||
dispatch({ | ||
type: actionTypes.FAIL, | ||
payload: error, | ||
error: true, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); | ||
return _context.abrupt("return", [error]); | ||
case 14: | ||
_context.prev = 14; | ||
_context.t0 = _context["catch"](3); | ||
error = internals$1.ensureError(_context.t0); | ||
dispatch({ | ||
type: actionTypes.FAIL, | ||
payload: error, | ||
error: true, | ||
meta: { | ||
original: beginPayload, | ||
index: index | ||
} | ||
}); | ||
return _context.abrupt("return", [error]); | ||
case 19: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, null, [[3, 14]]); | ||
})); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}() | ||
); | ||
case 19: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, null, null, [[3, 14]]); | ||
}; | ||
}; | ||
@@ -463,0 +459,0 @@ }; |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("redux"),require("normalizr"),require("redux-thunk"),require("immer")):"function"==typeof define&&define.amd?define(["exports","redux","normalizr","redux-thunk","immer"],r):r((e=e||self).StrangeMiddleEnd={},e.Redux,e.normalizr,e.ReduxThunk,e.immer)}(this,function(e,r,n,t,i){"use strict";function o(e,r,n,t,i,o,a){try{var u=e[o](a),c=u.value}catch(e){return void n(e)}u.done?r(c):Promise.resolve(c).then(t,i)}function a(e){return function(){var r=this,n=arguments;return new Promise(function(t,i){var a=e.apply(r,n);function u(e){o(a,t,i,u,c,"next",e)}function c(e){o(a,t,i,u,c,"throw",e)}u(void 0)})}}function u(e,r,n){return r in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function c(e,r){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),n.push.apply(n,t)}return n}function f(e){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?c(n,!0).forEach(function(r){u(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(n).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function l(e,r){return function(e){if(Array.isArray(e))return e}(e)||function(e,r){var n=[],t=!0,i=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(t=(a=u.next()).done)&&(n.push(a.value),!r||n.length!==r);t=!0);}catch(e){i=!0,o=e}finally{try{t||null==u.return||u.return()}finally{if(i)throw o}}return n}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function s(e){return function(e){if(Array.isArray(e)){for(var r=0,n=new Array(e.length);r<e.length;r++)n[r]=e[r];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}t=t&&t.hasOwnProperty("default")?t.default:t;var d={},p={thunk:t,errorLogger:function(){return function(e){return function(r){var n=r.type,t=r.error,i=r.payload,o=r.meta;return t&&console.error('Error from action "'.concat(n,'"'),o,"\n",i),e(r)}}}};d.pickEach=function(e,r){return Object.entries(e).filter(function(e){var n=l(e,2)[1];return n&&void 0!==n[r]}).reduce(function(e,n){var t=l(n,2);return f({},e,u({},t[0],t[1][r]))},{})};var y={};y.simpleAction=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"function"==typeof r&&(r={transform:r});var n=r,t=n.transform,i=void 0===t?y.defaultTransform:t;return function(){return{type:e,payload:i.apply(void 0,arguments)}}},y.asyncAction=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"function"==typeof r&&(r={handler:r});var t=r,i=t.handler,o=void 0===i?y.defaultTransform:i,u=t.transform,c=void 0===u?y.defaultTransform:u,f=t.after,l=t.schema,d=t.index,p=void 0!==d&&d;return function(){for(var r=arguments.length,t=new Array(r),i=0;i<r;i++)t[i]=arguments[i];return function(){var r=a(regeneratorRuntime.mark(function r(i){var a,u,d,v,h;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return a=c.apply(void 0,t),u=[].concat(a),d=p?"string"==typeof p?p:"function"==typeof p?p.apply(void 0,s(u)):e.BASE:null,r.prev=3,i({type:e.BEGIN,payload:a,meta:{index:d}}),r.next=7,o.apply(void 0,s(u));case 7:return v=r.sent,l&&(v=n.normalize(v,l)),i({type:e.SUCCESS,payload:v,meta:{original:a,index:d}}),f&&f({original:a,result:v}),r.abrupt("return",[null,v]);case 14:return r.prev=14,r.t0=r.catch(3),h=y.ensureError(r.t0),i({type:e.FAIL,payload:h,error:!0,meta:{original:a,index:d}}),r.abrupt("return",[h]);case 19:case"end":return r.stop()}},r,null,[[3,14]])}));return function(e){return r.apply(this,arguments)}}()}},y.defaultTransform=function(){for(var e=arguments.length,r=new Array(e),n=0;n<e;n++)r[n]=arguments[n];return r.length<=1?r[0]:r},y.ensureError=function(e){if(e instanceof Error)return e;var r=new Error(e.message);return r.data=e,r};var v=function(e){return e.endsWith("/BEGIN")},h=function(e){return e.endsWith("/SUCCESS")},m=function(e){return e.endsWith("/FAIL")},g={};g.defaultShouldMerge=function(e){return Boolean(e._top)},g.getInitialEntityState=function(e){return Object.values(e).filter(function(e){return e instanceof n.schema.Entity}).reduce(function(e,r){return f({},e,u({},r.key,{}))},{})},g.isNormalizedPayload=function(e){return e&&e.hasOwnProperty("result")&&e.entities};var b=function(t){var i=t.createStore,o=t.mods,a=void 0===o?{}:o,u={initialized:!1,initialize:function(){return!1!==u.initialized?u:(u.initialized=null,Object.values(d.pickEach(u.mods,"schema")).forEach(function(r){Object.values(r).filter(function(e){return e instanceof n.schema.Entity}).forEach(function(n){n.relatedFields=function(){for(var r,t=arguments.length,i=new Array(t),o=0;o<t;o++)i[o]=arguments[o];return(r=e).relatedFields.apply(r,i.concat([{idAttribute:n.idAttribute}]))},n.relations&&n.define(n.relations(r))})}),Object.values(u.mods).filter(function(e){return e&&e.initialize}).forEach(function(e){return e.initialize(u,e)}),u.initialized=!0,u)}},c=function(e,r){Object.defineProperty(u,e,{configurable:!0,enumerable:!0,get:function(){if(!1===u.initialized)throw new Error('Cannot access property "'.concat(e,'" until middle-end is initialized.'));var n=r();return Object.defineProperty(u,e,{value:n,writable:!0}),n}})};return c("mods",function(){return"function"==typeof a?a():a}),c("store",function(){var e=r.combineReducers(d.pickEach(u.mods,"reducer"));return i(e,u.mods)}),c("getState",function(){return u.store.getState}),c("dispatch",function(){var e=function(){var e;return(e=u.store).dispatch.apply(e,arguments)};return Object.entries(u.actions).forEach(function(r){var n=l(r,2),t=n[0],i=n[1];e[t]={},Object.entries(i).forEach(function(r){var n=l(r,2),i=n[0],o=n[1];e[t][i]=function(){return e(o.apply(void 0,arguments))}})}),e}),c("actions",function(){return d.pickEach(u.mods,"actions")}),c("selectors",function(){return d.pickEach(u.mods,"selectors")}),u},E=p,O=function(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},t=n.idAttribute,i=void 0===t?"id":t,o=u({},i,e[i]);return r.forEach(function(r){e.hasOwnProperty(r)&&(o[r]=e[r])}),Object.keys(o).length>1?o:void 0},w=function(e,r){return"string"==typeof e?y.simpleAction(e,r):y.asyncAction(e,r)},S=function(e,r){return r||(r=e,e=null),e=e?"".concat(e,"/"):"",Object.entries(r).reduce(function(r,n){var t=l(n,2),i=t[0],o=t[1],a="".concat(e).concat(i);return o.isAsync?f({},r,u({},i,{BASE:a,BEGIN:"".concat(a,"/BEGIN"),SUCCESS:"".concat(a,"/SUCCESS"),FAIL:"".concat(a,"/FAIL")})):o.isSimple||!0===o?f({},r,u({},i,a)):f({},r,u({},i,o))},{})},j={async:{isAsync:!0},simple:{isSimple:!0}},A=function(e,r){return e.startsWith("".concat(r,"/"))||e===r},x=v,P=h,k=m,z=function(e,r,n){if(void 0===n&&(n=r,r=e,e={}),n.hasOwnProperty("undefined"))throw new Error("Reducer has an undefined handler. Ensure that all actions used in this reducer exist.");var t=e.mutable;void 0!==t&&t&&(n=f({},n),Object.keys(n).forEach(function(e){n[e]=i.produce(n[e])}));var o=function(e){return"function"==typeof e?e():e};return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(r),t=arguments.length>1?arguments[1]:void 0;return n.hasOwnProperty(t.type)?n[t.type](e,t):e}},I=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=e.schema,t=void 0===n?{}:n,o=e.shouldMerge,a=void 0===o?g.defaultShouldMerge:o,u=e.shouldIndex,c=void 0===u||u,f="function"==typeof a?a:function(){return a},s="function"==typeof c?c:function(){return c};return r.combineReducers({indexes:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0,n=r.type,t=r.payload,o=r.error,a=r.meta;return a&&a.index&&s(a.index)?i.produce(e,function(e){var r=e[a.index]=e[a.index]||{original:void 0,result:void 0,error:null,inFlight:0};v(n)&&(r.inFlight++,r.original=t),(h(n)||m(n))&&(r.inFlight--,a.hasOwnProperty("original")&&(r.original=a.original)),h(n)&&(r.result=g.isNormalizedPayload(t)?t.result:t,r.error=null),o&&(r.error=t||!0)}):e},entities:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:g.getInitialEntityState(t),r=arguments.length>1?arguments[1]:void 0,n=r.payload,o=r.error;return o||!g.isNormalizedPayload(n)?e:i.produce(e,function(r){var t=n.entities;Object.keys(t).forEach(function(n){e[n]&&Object.keys(t[n]).forEach(function(e){var i=t[n][e];f(i)?(r[n][e]=r[n][e]||{},Object.entries(i).forEach(function(t){var i=l(t,2),o=i[0],a=i[1];void 0!==a&&(r[n][e][o]=a)})):r[n][e]=i})})})}})};e.create=b,e.createAction=w,e.createEntityReducer=I,e.createReducer=z,e.createTypes=S,e.isTypeBegin=x,e.isTypeFail=k,e.isTypeOfBase=A,e.isTypeSuccess=P,e.middleware=E,e.relatedFields=O,e.type=j}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("redux"),require("normalizr"),require("redux-thunk"),require("immer")):"function"==typeof define&&define.amd?define(["exports","redux","normalizr","redux-thunk","immer"],t):t((e=e||self).StrangeMiddleEnd={},e.Redux,e.normalizr,e.ReduxThunk,e.immer)}(this,(function(e,t,r,n,i){"use strict";function o(e){return(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})(e)}function a(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function c(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(r,!0).forEach((function(t){a(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(r).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){if(!(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e)))return;var r=[],n=!0,i=!1,o=void 0;try{for(var a,u=e[Symbol.iterator]();!(n=(a=u.next()).done)&&(r.push(a.value),!t||r.length!==t);n=!0);}catch(e){i=!0,o=e}finally{try{n||null==u.return||u.return()}finally{if(i)throw o}}return r}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function l(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}n=n&&n.hasOwnProperty("default")?n.default:n;var s={},d={thunk:n,errorLogger:function(){return function(e){return function(t){var r=t.type,n=t.error,i=t.payload,o=t.meta;return n&&console.error('Error from action "'.concat(r,'"'),o,"\n",i),e(t)}}}};s.pickEach=function(e,t){return Object.entries(e).filter((function(e){var r=f(e,2)[1];return r&&void 0!==r[t]})).reduce((function(e,r){var n=f(r,2);return c({},e,a({},n[0],n[1][t]))}),{})},s.mapEachLeafFunction=function(e,t){return Object.entries(e).reduce((function(e,r){var n=f(r,2),i=n[0],u=n[1];return c({},e,a({},i,"function"==typeof u?t(u):u&&"object"===o(u)?s.mapEachLeafFunction(u,t):u))}),{})};var p={};p.simpleAction=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"function"==typeof t&&(t={transform:t});var r=t,n=r.transform,i=void 0===n?p.defaultTransform:n;return function(){return{type:e,payload:i.apply(void 0,arguments)}}},p.asyncAction=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};"function"==typeof t&&(t={handler:t});var n=t,i=n.handler,o=void 0===i?p.defaultTransform:i,a=n.transform,u=void 0===a?p.defaultTransform:a,c=n.after,f=n.schema,s=n.index,d=void 0!==s&&s;return function(){for(var t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return function(t){var i,a,s,y,v;return regeneratorRuntime.async((function(h){for(;;)switch(h.prev=h.next){case 0:return i=u.apply(void 0,n),a=[].concat(i),s=d?"string"==typeof d?d:"function"==typeof d?d.apply(void 0,l(a)):e.BASE:null,h.prev=3,t({type:e.BEGIN,payload:i,meta:{index:s}}),h.next=7,regeneratorRuntime.awrap(o.apply(void 0,l(a)));case 7:return y=h.sent,f&&(y=r.normalize(y,f)),t({type:e.SUCCESS,payload:y,meta:{original:i,index:s}}),c&&c({original:i,result:y}),h.abrupt("return",[null,y]);case 14:return h.prev=14,h.t0=h.catch(3),v=p.ensureError(h.t0),t({type:e.FAIL,payload:v,error:!0,meta:{original:i,index:s}}),h.abrupt("return",[v]);case 19:case"end":return h.stop()}}),null,null,[[3,14]])}}},p.defaultTransform=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.length<=1?t[0]:t},p.ensureError=function(e){if(e instanceof Error)return e;var t=new Error(e.message);return t.data=e,t};var y=function(e){return e.endsWith("/BEGIN")},v=function(e){return e.endsWith("/SUCCESS")},h=function(e){return e.endsWith("/FAIL")},m={};m.defaultShouldMerge=function(e){return Boolean(e._top)},m.getInitialEntityState=function(e){return Object.values(e).filter((function(e){return e instanceof r.schema.Entity})).reduce((function(e,t){return c({},e,a({},t.key,{}))}),{})},m.isNormalizedPayload=function(e){return e&&e.hasOwnProperty("result")&&e.entities};var b=function(n){var i=n.createStore,o=n.mods,a=void 0===o?{}:o,u={initialized:!1,initialize:function(){return!1!==u.initialized?u:(u.initialized=null,Object.values(s.pickEach(u.mods,"schema")).forEach((function(t){Object.values(t).filter((function(e){return e instanceof r.schema.Entity})).forEach((function(r){r.relatedFields=function(){for(var t,n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];return(t=e).relatedFields.apply(t,i.concat([{idAttribute:r.idAttribute}]))},r.relations&&r.define(r.relations(t))}))})),Object.values(u.mods).filter((function(e){return e&&e.initialize})).forEach((function(e){return e.initialize(u,e)})),u.initialized=!0,u)}},c=function(e,t){Object.defineProperty(u,e,{configurable:!0,enumerable:!0,get:function(){if(!1===u.initialized)throw new Error('Cannot access property "'.concat(e,'" until middle-end is initialized.'));var r=t();return Object.defineProperty(u,e,{value:r,writable:!0}),r}})};return c("mods",(function(){return"function"==typeof a?a():a})),c("store",(function(){var e=t.combineReducers(s.pickEach(u.mods,"reducer"));return i(e,u.mods)})),c("getState",(function(){return u.store.getState})),c("dispatch",(function(){var e=function(){var e;return(e=u.store).dispatch.apply(e,arguments)};return Object.entries(u.actions).forEach((function(t){var r=f(t,2),n=r[0],i=r[1];e[n]={},Object.entries(i).forEach((function(t){var r=f(t,2),i=r[0],o=r[1];e[n][i]=function(){return e(o.apply(void 0,arguments))}}))})),e})),c("actions",(function(){return s.pickEach(u.mods,"actions")})),c("select",(function(){var e=u.selectors,t=u.getState;return s.mapEachLeafFunction(e,(function(e){return function(){for(var r=arguments.length,n=new Array(r),i=0;i<r;i++)n[i]=arguments[i];return e.apply(void 0,[t()].concat(n))}}))})),c("selectors",(function(){return s.pickEach(u.mods,"selectors")})),u},g=d,E=function(e,t){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},n=r.idAttribute,i=void 0===n?"id":n,o=a({},i,e[i]);return t.forEach((function(t){e.hasOwnProperty(t)&&(o[t]=e[t])})),Object.keys(o).length>1?o:void 0},O=function(e,t){return"string"==typeof e?p.simpleAction(e,t):p.asyncAction(e,t)},S=function(e,t){return t||(t=e,e=null),e=e?"".concat(e,"/"):"",Object.entries(t).reduce((function(t,r){var n=f(r,2),i=n[0],o=n[1],u="".concat(e).concat(i);return o.isAsync?c({},t,a({},i,{BASE:u,BEGIN:"".concat(u,"/BEGIN"),SUCCESS:"".concat(u,"/SUCCESS"),FAIL:"".concat(u,"/FAIL")})):o.isSimple||!0===o?c({},t,a({},i,u)):c({},t,a({},i,o))}),{})},j={async:{isAsync:!0},simple:{isSimple:!0}},w=function(e,t){return e.startsWith("".concat(t,"/"))||e===t},A=y,x=v,P=h,z=function(e,t,r){if(void 0===r&&(r=t,t=e,e={}),r.hasOwnProperty("undefined"))throw new Error("Reducer has an undefined handler. Ensure that all actions used in this reducer exist.");var n=e.mutable;void 0!==n&&n&&(r=c({},r),Object.keys(r).forEach((function(e){r[e]=i.produce(r[e])})));var o=function(e){return"function"==typeof e?e():e};return function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(t),n=arguments.length>1?arguments[1]:void 0;return r.hasOwnProperty(n.type)?r[n.type](e,n):e}},k=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.schema,n=void 0===r?{}:r,o=e.shouldMerge,a=void 0===o?m.defaultShouldMerge:o,u=e.shouldIndex,c=void 0===u||u,l="function"==typeof a?a:function(){return a},s="function"==typeof c?c:function(){return c};return t.combineReducers({indexes:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t=arguments.length>1?arguments[1]:void 0,r=t.type,n=t.payload,o=t.error,a=t.meta;return a&&a.index&&s(a.index)?i.produce(e,(function(e){var t=e[a.index]=e[a.index]||{original:void 0,result:void 0,error:null,inFlight:0};y(r)&&(t.inFlight++,t.original=n),(v(r)||h(r))&&(t.inFlight--,a.hasOwnProperty("original")&&(t.original=a.original)),v(r)&&(t.result=m.isNormalizedPayload(n)?n.result:n,t.error=null),o&&(t.error=n||!0)})):e},entities:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:m.getInitialEntityState(n),t=arguments.length>1?arguments[1]:void 0,r=t.payload,o=t.error;return o||!m.isNormalizedPayload(r)?e:i.produce(e,(function(t){var n=r.entities;Object.keys(n).forEach((function(r){e[r]&&Object.keys(n[r]).forEach((function(e){var i=n[r][e];l(i)?(t[r][e]=t[r][e]||{},Object.entries(i).forEach((function(n){var i=f(n,2),o=i[0],a=i[1];void 0!==a&&(t[r][e][o]=a)}))):t[r][e]=i}))}))}))}})};e.create=b,e.createAction=O,e.createEntityReducer=k,e.createReducer=z,e.createTypes=S,e.isTypeBegin=A,e.isTypeFail=P,e.isTypeOfBase=w,e.isTypeSuccess=x,e.middleware=g,e.relatedFields=E,e.type=j})); | ||
//# sourceMappingURL=strange-middle-end.umd.min.js.map |
@@ -28,2 +28,3 @@ 'use strict'; | ||
middleEnd.actions; | ||
middleEnd.select; | ||
middleEnd.selectors; | ||
@@ -122,2 +123,15 @@ | ||
initializedProp('select', () => { | ||
const { selectors, getState } = middleEnd; | ||
// Convenient selection, | ||
// select.auth.isAuthenticated() versus selectors.auth.isAuthenticated(getState()) | ||
return internals.mapEachLeafFunction(selectors, (selector) => { | ||
return (...args) => selector(getState(), ...args); | ||
}); | ||
}); | ||
initializedProp('selectors', () => { | ||
@@ -172,1 +186,16 @@ | ||
}; | ||
internals.mapEachLeafFunction = (obj, map) => { | ||
return Object.entries(obj).reduce((collect, [key, value]) => { | ||
return { | ||
...collect, | ||
[key]: typeof value === 'function' ? | ||
map(value) : | ||
(value && typeof value === 'object') ? | ||
internals.mapEachLeafFunction(value, map) : | ||
value | ||
}; | ||
}, {}); | ||
}; |
{ | ||
"name": "strange-middle-end", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "a middle-end composer using redux, normalizr, and immer", | ||
@@ -39,10 +39,10 @@ "main": "dist/strange-middle-end.js", | ||
"redux-thunk": "2.x.x", | ||
"immer": ">=1 <4", | ||
"immer": ">=1 <6", | ||
"normalizr": "3.x.x" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@hapi/code": "6.x.x", | ||
"@hapi/lab": "20.x.x", | ||
"@babel/core": "7.x.x", | ||
"@babel/preset-env": "7.x.x", | ||
"@hapi/code": "7.x.x", | ||
"@hapi/lab": "21.x.x", | ||
"coveralls": "3.x.x", | ||
@@ -58,3 +58,3 @@ "redux": "4.x.x", | ||
"rollup-plugin-terser": "5.x.x", | ||
"immer": "3.x.x", | ||
"immer": "5.x.x", | ||
"normalizr": "3.x.x", | ||
@@ -61,0 +61,0 @@ "npm-run-all": "4.x.x", |
@@ -24,3 +24,3 @@ # strange-middle-end | ||
const { FETCH_USER, INCREMENT } = MiddleEnd.createTypes({ | ||
const { INCREMENT, FETCH_USER } = MiddleEnd.createTypes({ | ||
INCREMENT: MiddleEnd.type.simple, | ||
@@ -146,3 +146,3 @@ FETCH_USER: MiddleEnd.type.async | ||
console.log(app.selectors.model.getUser(app.getState())); | ||
console.log(app.select.model.getUser()); | ||
@@ -149,0 +149,0 @@ app.dispatch.counter.increment(); |
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
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
156420
1640
1