Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-base-table

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-base-table - npm Package Compare versions

Comparing version 1.2.1 to 1.2.2

4

CHANGELOG.md

@@ -5,2 +5,6 @@ # CHANGELOG

# v1.2.2 (2019-05-03)
- perf: optimize `unflatten` and `flattenOnKeys` to not use recursion
# v1.2.1 (2019-05-01)

@@ -7,0 +11,0 @@

2

es/BaseTable.js

@@ -92,3 +92,3 @@ 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; }

_this._depthMap = {};
return flattenOnKeys(tree, keys, _this._depthMap, 0, dataKey);
return flattenOnKeys(tree, keys, _this._depthMap, dataKey);
});

@@ -95,0 +95,0 @@ _this._scroll = {};

@@ -69,5 +69,5 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

}
export function unflatten(array, parent, dataKey, parentKey) {
if (parent === void 0) {
parent = null;
export function unflatten(array, rootId, dataKey, parentKey) {
if (rootId === void 0) {
rootId = null;
}

@@ -83,15 +83,25 @@

// deep clone the array
var tree = Array.prototype.filter.call(array, function (x) {
return x[parentKey] === parent;
}).map(function (x) {
return _objectSpread({}, x);
});
tree.forEach(function (child) {
var childTree = unflatten(array, child[dataKey], dataKey, parentKey);
if (childTree.length > 0) child.children = childTree;
});
var tree = [];
var childrenMap = {};
var length = array.length;
for (var i = 0; i < length; i++) {
var item = _objectSpread({}, array[i]);
var id = item[dataKey];
var parentId = item[parentKey];
if (!childrenMap[id]) childrenMap[id] = [];
item.children = childrenMap[id];
if (parentId !== rootId) {
if (!childrenMap[parentId]) childrenMap[parentId] = [];
childrenMap[parentId].push(item);
} else {
tree.push(item);
}
}
return tree;
}
export function flattenOnKeys(tree, keys, depthMap, depth, dataKey) {
export function flattenOnKeys(tree, keys, depthMap, dataKey) {
if (depthMap === void 0) {

@@ -101,6 +111,2 @@ depthMap = {};

if (depth === void 0) {
depth = 0;
}
if (dataKey === void 0) {

@@ -112,16 +118,27 @@ dataKey = 'id';

var array = [];
tree.forEach(function (child) {
array.push(child);
var keysSet = new Set();
keys.forEach(function (x) {
return keysSet.add(x);
});
var stack = [].concat(tree);
stack.forEach(function (x) {
return depthMap[x[dataKey]] = 0;
});
if (keys.indexOf(child[dataKey]) >= 0) {
depthMap[child[dataKey]] = depth;
var _loop = function _loop() {
var item = stack.shift();
array.push(item);
if (hasChildren(child)) {
child.children.forEach(function (x) {
depthMap[x[dataKey]] = depth + 1;
});
array = array.concat(flattenOnKeys(child.children, keys, depthMap, depth + 1, dataKey));
}
if (keysSet.has(item[dataKey]) && Array.isArray(item.children) && item.children.length > 0) {
stack = item.children.concat(stack);
item.children.forEach(function (x) {
return depthMap[x[dataKey]] = depthMap[item[dataKey]] + 1;
});
}
});
};
while (stack.length > 0) {
_loop();
}
return array;

@@ -128,0 +145,0 @@ } // Babel7 changed the behavior of @babel/plugin-transform-spread in https://github.com/babel/babel/pull/6763

@@ -137,3 +137,3 @@ "use strict";

_this._depthMap = {};
return (0, _utils.flattenOnKeys)(tree, keys, _this._depthMap, 0, dataKey);
return (0, _utils.flattenOnKeys)(tree, keys, _this._depthMap, dataKey);
});

@@ -140,0 +140,0 @@ _this._scroll = {};

@@ -98,15 +98,25 @@ "use strict";

function unflatten(array) {
var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var rootId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var dataKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'id';
var parentKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'parentId';
// deep clone the array
var tree = Array.prototype.filter.call(array, function (x) {
return x[parentKey] === parent;
}).map(function (x) {
return _objectSpread({}, x);
});
tree.forEach(function (child) {
var childTree = unflatten(array, child[dataKey], dataKey, parentKey);
if (childTree.length > 0) child.children = childTree;
});
var tree = [];
var childrenMap = {};
var length = array.length;
for (var i = 0; i < length; i++) {
var item = _objectSpread({}, array[i]);
var id = item[dataKey];
var parentId = item[parentKey];
if (!childrenMap[id]) childrenMap[id] = [];
item.children = childrenMap[id];
if (parentId !== rootId) {
if (!childrenMap[parentId]) childrenMap[parentId] = [];
childrenMap[parentId].push(item);
} else {
tree.push(item);
}
}
return tree;

@@ -117,20 +127,30 @@ }

var depthMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var depth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
var dataKey = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'id';
var dataKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'id';
if (!keys || !keys.length) return tree;
var array = [];
tree.forEach(function (child) {
array.push(child);
var keysSet = new Set();
keys.forEach(function (x) {
return keysSet.add(x);
});
var stack = [].concat(tree);
stack.forEach(function (x) {
return depthMap[x[dataKey]] = 0;
});
if (keys.indexOf(child[dataKey]) >= 0) {
depthMap[child[dataKey]] = depth;
var _loop = function _loop() {
var item = stack.shift();
array.push(item);
if (hasChildren(child)) {
child.children.forEach(function (x) {
depthMap[x[dataKey]] = depth + 1;
});
array = array.concat(flattenOnKeys(child.children, keys, depthMap, depth + 1, dataKey));
}
if (keysSet.has(item[dataKey]) && Array.isArray(item.children) && item.children.length > 0) {
stack = item.children.concat(stack);
item.children.forEach(function (x) {
return depthMap[x[dataKey]] = depthMap[item[dataKey]] + 1;
});
}
});
};
while (stack.length > 0) {
_loop();
}
return array;

@@ -137,0 +157,0 @@ } // Babel7 changed the behavior of @babel/plugin-transform-spread in https://github.com/babel/babel/pull/6763

{
"name": "react-base-table",
"version": "1.2.1",
"version": "1.2.2",
"description": "a react table component to display large data set with high performance and flexibility",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc