data-joint
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -22,2 +22,72 @@ 'use strict'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
@@ -48,2 +118,6 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -120,3 +194,5 @@ var _n = true; | ||
dataBindAttr = _ref3$dataBindAttr === void 0 ? '__data' : _ref3$dataBindAttr, | ||
idAccessor = _ref3.idAccessor; | ||
idAccessor = _ref3.idAccessor, | ||
_ref3$purge = _ref3.purge, | ||
purge = _ref3$purge === void 0 ? false : _ref3$purge; | ||
@@ -134,3 +210,8 @@ var isObjValid = function isObjValid(obj) { | ||
var nextD = data; | ||
var diff = diffArrays(prevD, nextD, idAccessor); | ||
var diff = purge ? { | ||
enter: nextD, | ||
exit: prevD, | ||
update: [] | ||
} // don't diff data in purge mode | ||
: diffArrays(prevD, nextD, idAccessor); | ||
diff.update = diff.update.map(function (_ref4) { | ||
@@ -171,9 +252,8 @@ var _ref5 = _slicedToArray(_ref4, 2), | ||
dataBindAttr = _ref7$dataBindAttr === void 0 ? '__data' : _ref7$dataBindAttr, | ||
idAccessor = _ref7.idAccessor; | ||
dataDiffOptions = _objectWithoutProperties(_ref7, ["createObj", "updateObj", "exitObj", "objBindAttr", "dataBindAttr"]); | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, { | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, _objectSpread2({ | ||
objBindAttr: objBindAttr, | ||
dataBindAttr: dataBindAttr, | ||
idAccessor: idAccessor | ||
}), | ||
dataBindAttr: dataBindAttr | ||
}, dataDiffOptions)), | ||
enter = _dataBindDiff.enter, | ||
@@ -180,0 +260,0 @@ update = _dataBindDiff.update, |
@@ -1,2 +0,2 @@ | ||
// Version 1.1.0 data-joint - https://github.com/vasturiano/data-joint | ||
// Version 1.2.0 data-joint - https://github.com/vasturiano/data-joint | ||
(function (global, factory) { | ||
@@ -23,2 +23,72 @@ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
@@ -49,2 +119,6 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -83,19 +157,213 @@ var _n = true; | ||
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; | ||
function _objectWithoutPropertiesLoose$1(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
function unwrapExports (x) { | ||
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
function _objectWithoutProperties$1(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose$1(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
var indexArrayBy_min = createCommonjsModule(function (module, exports) { | ||
!function(r,e){module.exports=e();}("undefined"!=typeof self?self:commonjsGlobal,function(){return function(t){var n={};function o(r){if(n[r])return n[r].exports;var e=n[r]={i:r,l:!1,exports:{}};return t[r].call(e.exports,e,e.exports,o),e.l=!0,e.exports}return o.m=t,o.c=n,o.d=function(r,e,t){o.o(r,e)||Object.defineProperty(r,e,{configurable:!1,enumerable:!0,get:t});},o.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return o.d(e,"a",e),e},o.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},o.p="",o(o.s=0)}([function(r,e,t){var n,o,i;o=[r,e],void 0===(i="function"==typeof(n=function(r,e){Object.defineProperty(e,"__esModule",{value:!0});var f=function(r,e){if(Array.isArray(r))return r;if(Symbol.iterator in Object(r))return function(r,e){var t=[],n=!0,o=!1,i=void 0;try{for(var u,f=r[Symbol.iterator]();!(n=(u=f.next()).done)&&(t.push(u.value),!e||t.length!==e);n=!0);}catch(r){o=!0,i=r;}finally{try{!n&&f.return&&f.return();}finally{if(o)throw i}}return t}(r,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")};e.default=function(r,e){var a=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],t=3<arguments.length&&void 0!==arguments[3]&&arguments[3],s=(e instanceof Array?e:[e]).map(function(r){return {keyAccessor:r,isProp:!(r instanceof Function)}}),n=r.reduce(function(r,e){var f=r,c=e;return s.forEach(function(r,e){var t=r.keyAccessor,n=void 0;if(r.isProp){var o=c,i=o[t],u=function(r,e){var t={};for(var n in r)0<=e.indexOf(n)||Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t}(o,[t]);n=i,c=u;}else n=t(c,e);e+1<s.length?(f.hasOwnProperty(n)||(f[n]={}),f=f[n]):a?(f.hasOwnProperty(n)||(f[n]=[]),f[n].push(c)):f[n]=c;}),r},{});a instanceof Function&&function e(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;n===s.length?Object.keys(t).forEach(function(r){return t[r]=a(t[r])}):Object.values(t).forEach(function(r){return e(r,n+1)});}(n);var u=n;return t&&(u=[],function o(r){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[];i.length===s.length?u.push({keys:i,vals:r}):Object.entries(r).forEach(function(r){var e=f(r,2),t=e[0],n=e[1];return o(n,[].concat(function(r){if(Array.isArray(r)){for(var e=0,t=Array(r.length);e<r.length;e++)t[e]=r[e];return t}return Array.from(r)}(i),[t]))});}(n)),u},r.exports=e.default;})?n.apply(e,o):n)||(r.exports=i);}])}); | ||
function _slicedToArray$1(arr, i) { | ||
return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _nonIterableRest$1(); | ||
} | ||
function _toConsumableArray$1(arr) { | ||
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1(); | ||
} | ||
function _arrayWithoutHoles$1(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _arrayWithHoles$1(arr) { | ||
if (Array.isArray(arr)) return arr; | ||
} | ||
function _iterableToArray$1(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _iterableToArrayLimit$1(arr, i) { | ||
var _arr = []; | ||
var _n = true; | ||
var _d = false; | ||
var _e = undefined; | ||
try { | ||
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { | ||
_arr.push(_s.value); | ||
if (i && _arr.length === i) break; | ||
} | ||
} catch (err) { | ||
_d = true; | ||
_e = err; | ||
} finally { | ||
try { | ||
if (!_n && _i["return"] != null) _i["return"](); | ||
} finally { | ||
if (_d) throw _e; | ||
} | ||
} | ||
return _arr; | ||
} | ||
function _nonIterableSpread$1() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function _nonIterableRest$1() { | ||
throw new TypeError("Invalid attempt to destructure non-iterable instance"); | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
var index = (function (list, keyAccessors) { | ||
var multiItem = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; | ||
var flattenKeys = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var keys = (keyAccessors instanceof Array ? keyAccessors : [keyAccessors]).map(function (key) { | ||
return { | ||
keyAccessor: key, | ||
isProp: !(key instanceof Function) | ||
}; | ||
}); | ||
var indexedResult = list.reduce(function (res, item) { | ||
var iterObj = res; | ||
var itemVal = item; | ||
keys.forEach(function (_ref, idx) { | ||
var keyAccessor = _ref.keyAccessor, | ||
isProp = _ref.isProp; | ||
var key; | ||
if (isProp) { | ||
var _itemVal = itemVal, | ||
propVal = _itemVal[keyAccessor], | ||
rest = _objectWithoutProperties$1(_itemVal, [keyAccessor].map(_toPropertyKey)); | ||
key = propVal; | ||
itemVal = rest; | ||
} else { | ||
key = keyAccessor(itemVal, idx); | ||
} | ||
if (idx + 1 < keys.length) { | ||
if (!iterObj.hasOwnProperty(key)) { | ||
iterObj[key] = {}; | ||
} | ||
iterObj = iterObj[key]; | ||
} else { | ||
// Leaf key | ||
if (multiItem) { | ||
if (!iterObj.hasOwnProperty(key)) { | ||
iterObj[key] = []; | ||
} | ||
iterObj[key].push(itemVal); | ||
} else { | ||
iterObj[key] = itemVal; | ||
} | ||
} | ||
}); | ||
return res; | ||
}, {}); | ||
if (multiItem instanceof Function) { | ||
// Reduce leaf multiple values | ||
(function reduce(node) { | ||
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
if (level === keys.length) { | ||
Object.keys(node).forEach(function (k) { | ||
return node[k] = multiItem(node[k]); | ||
}); | ||
} else { | ||
Object.values(node).forEach(function (child) { | ||
return reduce(child, level + 1); | ||
}); | ||
} | ||
})(indexedResult); // IIFE | ||
} | ||
var result = indexedResult; | ||
if (flattenKeys) { | ||
// flatten into array | ||
result = []; | ||
(function flatten(node) { | ||
var accKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
if (accKeys.length === keys.length) { | ||
result.push({ | ||
keys: accKeys, | ||
vals: node | ||
}); | ||
} else { | ||
Object.entries(node).forEach(function (_ref2) { | ||
var _ref3 = _slicedToArray$1(_ref2, 2), | ||
key = _ref3[0], | ||
val = _ref3[1]; | ||
return flatten(val, [].concat(_toConsumableArray$1(accKeys), [key])); | ||
}); | ||
} | ||
})(indexedResult); //IIFE | ||
} | ||
return result; | ||
}); | ||
var indexBy = unwrapExports(indexArrayBy_min); | ||
var indexArrayBy_min_1 = indexArrayBy_min.indexBy; | ||
function diffArrays(prev, next, idAccessor) { | ||
@@ -118,4 +386,4 @@ var result = { | ||
// compare by id (duplicate keys are ignored) | ||
var prevById = indexBy(prev, idAccessor, false); | ||
var nextById = indexBy(next, idAccessor, false); | ||
var prevById = index(prev, idAccessor, false); | ||
var nextById = index(next, idAccessor, false); | ||
var byId = Object.assign({}, prevById, nextById); | ||
@@ -140,3 +408,5 @@ Object.entries(byId).forEach(function (_ref) { | ||
dataBindAttr = _ref3$dataBindAttr === void 0 ? '__data' : _ref3$dataBindAttr, | ||
idAccessor = _ref3.idAccessor; | ||
idAccessor = _ref3.idAccessor, | ||
_ref3$purge = _ref3.purge, | ||
purge = _ref3$purge === void 0 ? false : _ref3$purge; | ||
@@ -154,3 +424,8 @@ var isObjValid = function isObjValid(obj) { | ||
var nextD = data; | ||
var diff = diffArrays(prevD, nextD, idAccessor); | ||
var diff = purge ? { | ||
enter: nextD, | ||
exit: prevD, | ||
update: [] | ||
} // don't diff data in purge mode | ||
: diffArrays(prevD, nextD, idAccessor); | ||
diff.update = diff.update.map(function (_ref4) { | ||
@@ -191,9 +466,8 @@ var _ref5 = _slicedToArray(_ref4, 2), | ||
dataBindAttr = _ref7$dataBindAttr === void 0 ? '__data' : _ref7$dataBindAttr, | ||
idAccessor = _ref7.idAccessor; | ||
dataDiffOptions = _objectWithoutProperties(_ref7, ["createObj", "updateObj", "exitObj", "objBindAttr", "dataBindAttr"]); | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, { | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, _objectSpread2({ | ||
objBindAttr: objBindAttr, | ||
dataBindAttr: dataBindAttr, | ||
idAccessor: idAccessor | ||
}), | ||
dataBindAttr: dataBindAttr | ||
}, dataDiffOptions)), | ||
enter = _dataBindDiff.enter, | ||
@@ -200,0 +474,0 @@ update = _dataBindDiff.update, |
@@ -1,2 +0,2 @@ | ||
// Version 1.1.0 data-joint - https://github.com/vasturiano/data-joint | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(t=t||self).dataJoint=n()}(this,function(){"use strict";function t(t,n){return function(t){if(Array.isArray(t))return t}(t)||function(t,n){var r=[],e=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);e=!0);}catch(t){o=!0,i=t}finally{try{e||null==u.return||u.return()}finally{if(o)throw i}}return r}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function n(t){return function(t){if(Array.isArray(t)){for(var n=0,r=new Array(t.length);n<t.length;n++)r[n]=t[n];return r}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var r,e=function(t,n){return t(n={exports:{}},n.exports),n.exports}(function(t,n){"undefined"!=typeof self&&self,t.exports=function(t){var n={};function r(e){if(n[e])return n[e].exports;var o=n[e]={i:e,l:!1,exports:{}};return t[e].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=n,r.d=function(t,n,e){r.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:e})},r.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(n,"a",n),n},r.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},r.p="",r(r.s=0)}([function(t,n,r){var e,o,i;o=[t,n],void 0===(i="function"==typeof(e=function(t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(t,n){var r=!(2<arguments.length&&void 0!==arguments[2])||arguments[2],e=3<arguments.length&&void 0!==arguments[3]&&arguments[3],o=(n instanceof Array?n:[n]).map(function(t){return{keyAccessor:t,isProp:!(t instanceof Function)}}),i=t.reduce(function(t,n){var e=t,i=n;return o.forEach(function(t,n){var a=t.keyAccessor,u=void 0;if(t.isProp){var f=i,c=f[a],l=function(t,n){var r={};for(var e in t)0<=n.indexOf(e)||Object.prototype.hasOwnProperty.call(t,e)&&(r[e]=t[e]);return r}(f,[a]);u=c,i=l}else u=a(i,n);n+1<o.length?(e.hasOwnProperty(u)||(e[u]={}),e=e[u]):r?(e.hasOwnProperty(u)||(e[u]=[]),e[u].push(i)):e[u]=i}),t},{});r instanceof Function&&function t(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:1;e===o.length?Object.keys(n).forEach(function(t){return n[t]=r(n[t])}):Object.values(n).forEach(function(n){return t(n,e+1)})}(i);var a=i;return e&&(a=[],function t(n){var r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[];r.length===o.length?a.push({keys:r,vals:n}):Object.entries(n).forEach(function(n){var e=function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,n){var r=[],e=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(e=(a=u.next()).done)&&(r.push(a.value),!n||r.length!==n);e=!0);}catch(t){o=!0,i=t}finally{try{!e&&u.return&&u.return()}finally{if(o)throw i}}return r}(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}(n,2),o=e[0],i=e[1];return t(i,[].concat(function(t){if(Array.isArray(t)){for(var n=0,r=Array(t.length);n<t.length;n++)r[n]=t[n];return r}return Array.from(t)}(r),[o]))})}(i)),a},t.exports=n.default})?e.apply(n,o):e)||(t.exports=i)}])}),o=(r=e)&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r;e.indexBy;function i(r,e,i){var a=i.objBindAttr,u=void 0===a?"__obj":a,f=i.dataBindAttr,c=void 0===f?"__data":f,l=i.idAccessor,d=function(t){return t.hasOwnProperty(c)},s=e.filter(function(t){return!d(t)}),p=function(r,e,i){var a={enter:[],update:[],exit:[]};if(i){var u=o(r,i,!1),f=o(e,i,!1),c=Object.assign({},u,f);Object.entries(c).forEach(function(n){var r=t(n,2),e=r[0],o=r[1],i=u.hasOwnProperty(e)?f.hasOwnProperty(e)?"update":"exit":"enter";a[i].push("update"===i?[u[e],f[e]]:o)})}else{var l=new Set(r),d=new Set(e);new Set([].concat(n(l),n(d))).forEach(function(t){var n=l.has(t)?d.has(t)?"update":"exit":"enter";a[n].push("update"===n?[t,t]:t)})}return a}(e.filter(d).map(function(t){return t[c]}),r,l);return p.update=p.update.map(function(n){var r=t(n,2),e=r[0],o=r[1];return e!==o&&(o[u]=e[u],o[u][c]=o),o}),p.exit=p.exit.concat(s.map(function(t){return function(t,n,r){return n in t?Object.defineProperty(t,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[n]=r,t}({},u,t)})),p}return function(t,r,e,o,a){var u=a.createObj,f=void 0===u?function(t){return{}}:u,c=a.updateObj,l=void 0===c?function(t,n){}:c,d=a.exitObj,s=void 0===d?function(t){}:d,p=a.objBindAttr,y=void 0===p?"__obj":p,v=a.dataBindAttr,h=void 0===v?"__data":v,b=a.idAccessor,O=i(t,r,{objBindAttr:y,dataBindAttr:h,idAccessor:b}),w=O.enter,A=O.update,g=O.exit,j=function(t){var n=[];return t.forEach(function(t){var r=f(t);r&&(r[h]=t,t[y]=r,n.push(r))}),n}(w);!function(t){t.forEach(function(t){var n=t[y];n&&(n[h]=t,l(n,t))})}([].concat(n(w),n(A))),j.forEach(e),g.forEach(function(t){var n=t[y];s(n),o(n)})}}); | ||
// Version 1.2.0 data-joint - https://github.com/vasturiano/data-joint | ||
!function(t,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(t=t||self).dataJoint=r()}(this,(function(){"use strict";function t(t,r,e){return r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e,t}function r(t,r){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);r&&(n=n.filter((function(r){return Object.getOwnPropertyDescriptor(t,r).enumerable}))),e.push.apply(e,n)}return e}function e(t,r){if(null==t)return{};var e,n,o=function(t,r){if(null==t)return{};var e,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e=i[n],r.indexOf(e)>=0||(o[e]=t[e]);return o}(t,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)e=i[n],r.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(t,e)&&(o[e]=t[e])}return o}function n(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){if(!(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t)))return;var e=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(e.push(a.value),!r||e.length!==r);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return e}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function o(t){return function(t){if(Array.isArray(t)){for(var r=0,e=new Array(t.length);r<t.length;r++)e[r]=t[r];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function i(t,r){if(null==t)return{};var e,n,o=function(t,r){if(null==t)return{};var e,n,o={},i=Object.keys(t);for(n=0;n<i.length;n++)e=i[n],r.indexOf(e)>=0||(o[e]=t[e]);return o}(t,r);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(n=0;n<i.length;n++)e=i[n],r.indexOf(e)>=0||Object.prototype.propertyIsEnumerable.call(t,e)&&(o[e]=t[e])}return o}function a(t,r){return function(t){if(Array.isArray(t))return t}(t)||function(t,r){var e=[],n=!0,o=!1,i=void 0;try{for(var a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)&&(e.push(a.value),!r||e.length!==r);n=!0);}catch(t){o=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(o)throw i}}return e}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")}()}function u(t){return function(t){if(Array.isArray(t)){for(var r=0,e=new Array(t.length);r<t.length;r++)e[r]=t[r];return e}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function c(t){var r=function(t,r){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,r||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==typeof r?r:String(r)}var f=function(t,r){var e=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=arguments.length>3&&void 0!==arguments[3]&&arguments[3],o=(r instanceof Array?r:[r]).map((function(t){return{keyAccessor:t,isProp:!(t instanceof Function)}})),f=t.reduce((function(t,r){var n=t,a=r;return o.forEach((function(t,r){var u,f=t.keyAccessor;if(t.isProp){var l=a,p=l[f],s=i(l,[f].map(c));u=p,a=s}else u=f(a,r);r+1<o.length?(n.hasOwnProperty(u)||(n[u]={}),n=n[u]):e?(n.hasOwnProperty(u)||(n[u]=[]),n[u].push(a)):n[u]=a})),t}),{});e instanceof Function&&function t(r){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;n===o.length?Object.keys(r).forEach((function(t){return r[t]=e(r[t])})):Object.values(r).forEach((function(r){return t(r,n+1)}))}(f);var l=f;return n&&(l=[],function t(r){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];e.length===o.length?l.push({keys:e,vals:r}):Object.entries(r).forEach((function(r){var n=a(r,2),o=n[0],i=n[1];return t(i,[].concat(u(e),[o]))}))}(f)),l};function l(r,e,i){var a=i.objBindAttr,u=void 0===a?"__obj":a,c=i.dataBindAttr,l=void 0===c?"__data":c,p=i.idAccessor,s=i.purge,y=void 0!==s&&s,b=function(t){return t.hasOwnProperty(l)},d=e.filter((function(t){return!b(t)})),v=e.filter(b).map((function(t){return t[l]})),h=y?{enter:r,exit:v,update:[]}:function(t,r,e){var i={enter:[],update:[],exit:[]};if(e){var a=f(t,e,!1),u=f(r,e,!1),c=Object.assign({},a,u);Object.entries(c).forEach((function(t){var r=n(t,2),e=r[0],o=r[1],c=a.hasOwnProperty(e)?u.hasOwnProperty(e)?"update":"exit":"enter";i[c].push("update"===c?[a[e],u[e]]:o)}))}else{var l=new Set(t),p=new Set(r);new Set([].concat(o(l),o(p))).forEach((function(t){var r=l.has(t)?p.has(t)?"update":"exit":"enter";i[r].push("update"===r?[t,t]:t)}))}return i}(v,r,p);return h.update=h.update.map((function(t){var r=n(t,2),e=r[0],o=r[1];return e!==o&&(o[u]=e[u],o[u][l]=o),o})),h.exit=h.exit.concat(d.map((function(r){return t({},u,r)}))),h}return function(n,i,a,u,c){var f=c.createObj,p=void 0===f?function(t){return{}}:f,s=c.updateObj,y=void 0===s?function(t,r){}:s,b=c.exitObj,d=void 0===b?function(t){}:b,v=c.objBindAttr,h=void 0===v?"__obj":v,O=c.dataBindAttr,j=void 0===O?"__data":O,g=e(c,["createObj","updateObj","exitObj","objBindAttr","dataBindAttr"]),m=l(n,i,function(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?r(o,!0).forEach((function(r){t(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):r(o).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}({objBindAttr:h,dataBindAttr:j},g)),w=m.enter,A=m.update,P=m.exit,S=function(t){var r=[];return t.forEach((function(t){var e=p(t);e&&(e[j]=t,t[h]=e,r.push(e))})),r}(w);!function(t){t.forEach((function(t){var r=t[h];r&&(r[j]=t,y(r,t))}))}([].concat(o(w),o(A))),S.forEach(a),P.forEach((function(t){var r=t[h];d(r),u(r)}))}})); |
@@ -18,2 +18,72 @@ import indexBy from 'index-array-by'; | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(source, true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(source).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function _objectWithoutProperties(source, excluded) { | ||
if (source == null) return {}; | ||
var target = _objectWithoutPropertiesLoose(source, excluded); | ||
var key, i; | ||
if (Object.getOwnPropertySymbols) { | ||
var sourceSymbolKeys = Object.getOwnPropertySymbols(source); | ||
for (i = 0; i < sourceSymbolKeys.length; i++) { | ||
key = sourceSymbolKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; | ||
target[key] = source[key]; | ||
} | ||
} | ||
return target; | ||
} | ||
function _slicedToArray(arr, i) { | ||
@@ -44,2 +114,6 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
function _iterableToArrayLimit(arr, i) { | ||
if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { | ||
return; | ||
} | ||
var _arr = []; | ||
@@ -116,3 +190,5 @@ var _n = true; | ||
dataBindAttr = _ref3$dataBindAttr === void 0 ? '__data' : _ref3$dataBindAttr, | ||
idAccessor = _ref3.idAccessor; | ||
idAccessor = _ref3.idAccessor, | ||
_ref3$purge = _ref3.purge, | ||
purge = _ref3$purge === void 0 ? false : _ref3$purge; | ||
@@ -130,3 +206,8 @@ var isObjValid = function isObjValid(obj) { | ||
var nextD = data; | ||
var diff = diffArrays(prevD, nextD, idAccessor); | ||
var diff = purge ? { | ||
enter: nextD, | ||
exit: prevD, | ||
update: [] | ||
} // don't diff data in purge mode | ||
: diffArrays(prevD, nextD, idAccessor); | ||
diff.update = diff.update.map(function (_ref4) { | ||
@@ -167,9 +248,8 @@ var _ref5 = _slicedToArray(_ref4, 2), | ||
dataBindAttr = _ref7$dataBindAttr === void 0 ? '__data' : _ref7$dataBindAttr, | ||
idAccessor = _ref7.idAccessor; | ||
dataDiffOptions = _objectWithoutProperties(_ref7, ["createObj", "updateObj", "exitObj", "objBindAttr", "dataBindAttr"]); | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, { | ||
var _dataBindDiff = dataBindDiff(data, existingObjs, _objectSpread2({ | ||
objBindAttr: objBindAttr, | ||
dataBindAttr: dataBindAttr, | ||
idAccessor: idAccessor | ||
}), | ||
dataBindAttr: dataBindAttr | ||
}, dataDiffOptions)), | ||
enter = _dataBindDiff.enter, | ||
@@ -176,0 +256,0 @@ update = _dataBindDiff.update, |
{ | ||
"name": "data-joint", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Perform data joins with any type of JS objects", | ||
@@ -41,16 +41,16 @@ "unpkg": "dist/data-joint.min.js", | ||
"dependencies": { | ||
"index-array-by": "^1.2.3" | ||
"index-array-by": "^1.2.6" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-proposal-class-properties": "^7.4.4", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"rimraf": "^2.6.3", | ||
"rollup": "^1.12.4", | ||
"rollup-plugin-babel": "^4.3.2", | ||
"rollup-plugin-commonjs": "^10.0.0", | ||
"rollup-plugin-node-resolve": "^5.0.0", | ||
"terser": "^4.0.0" | ||
"@babel/core": "^7.6.0", | ||
"@babel/plugin-proposal-class-properties": "^7.5.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.5.5", | ||
"@babel/preset-env": "^7.6.0", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^1.21.4", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-commonjs": "^10.1.0", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"terser": "^4.3.1" | ||
} | ||
} |
@@ -1,3 +0,8 @@ | ||
# data-joint | ||
data-joint | ||
========== | ||
[![NPM package][npm-img]][npm-url] | ||
[![Build Size][build-size-img]][build-size-url] | ||
[![Dependencies][dependencies-img]][dependencies-url] | ||
Library to perform data joins with any type of JavaScript objects. | ||
@@ -7,4 +12,2 @@ Useful in digest cycles where it's important to minimize changes to a view for performance reasons, such as DOM manipulation. | ||
[![NPM](https://nodei.co/npm/data-joint.png?compact=true)](https://nodei.co/npm/data-joint/) | ||
## Quick start | ||
@@ -68,3 +71,10 @@ | ||
| <b>idAccessor</b> | A data point accessor function to extract the point unique identifier. This is used for comparing data points across multiple iterations. If no `idAccessor` is supplied, the data point object reference will be used instead for comparisons. The data point is passed as single argument: `d => {...}`. The method should return a unique identifier. | `undefined` | | ||
| <b>purge</b> | A boolean value. If set to `true` it will bypass the data diffing, resulting in all the `existingObjs` being marked for removal and new objects created for the all the items in the input `data`. | `false` | | ||
[npm-img]: https://img.shields.io/npm/v/data-joint.svg | ||
[npm-url]: https://npmjs.org/package/data-joint | ||
[build-size-img]: https://img.shields.io/bundlephobia/minzip/data-joint.svg | ||
[build-size-url]: https://bundlephobia.com/result?p=data-joint | ||
[dependencies-img]: https://img.shields.io/david/vasturiano/data-joint.svg | ||
[dependencies-url]: https://david-dm.org/vasturiano/data-joint |
@@ -44,3 +44,4 @@ import indexBy from 'index-array-by'; | ||
dataBindAttr = '__data', | ||
idAccessor | ||
idAccessor, | ||
purge = false | ||
} | ||
@@ -55,3 +56,5 @@ ) { | ||
const diff = diffArrays(prevD, nextD, idAccessor); | ||
const diff = purge | ||
? { enter: nextD, exit: prevD, update: [] } // don't diff data in purge mode | ||
: diffArrays(prevD, nextD, idAccessor); | ||
@@ -84,6 +87,6 @@ diff.update = diff.update.map(([prevD, nextD]) => { | ||
dataBindAttr = '__data', | ||
idAccessor | ||
...dataDiffOptions | ||
} | ||
) { | ||
const { enter, update, exit } = dataBindDiff(data, existingObjs, { objBindAttr, dataBindAttr, idAccessor }); | ||
const { enter, update, exit } = dataBindDiff(data, existingObjs, { objBindAttr, dataBindAttr, ...dataDiffOptions }); | ||
@@ -90,0 +93,0 @@ const newObjs = createObjs(enter); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
69328
1017
79
Updatedindex-array-by@^1.2.6