Socket
Socket
Sign inDemoInstall

aspen-core

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.1-alpha.0 to 0.0.1-alpha.1

14

dist/Branch.js

@@ -6,16 +6,2 @@ "use strict";

class Branch extends Leaf_1.Leaf {
nodes;
/**
* A flag indicating the "intended" expansion status of this branch. If this is `true`, the branch
* is either already expanded OR is about to be expanded. Explained below.
*
* This value represents the "intended" expansion state not the "actual" expansion state. When
* `Tree#expand` is called, the value of this will be immediately become `true`, however because
* the child nodes of the branch in question might need to be loaded, the actual expansion won't
* take effect until the children are loaded. So in that interim time while children are loading,
* the branch isn't truly expanded even if the value is `true`.
*
* Depending on your use case you might want to rely on `Tree#isTrulyExpanded` for a "real-time" status.
*/
expanded;
constructor(id, parent, data, expanded) {

@@ -22,0 +8,0 @@ super(id, parent, data);

4

dist/FlatViewMap.js

@@ -5,6 +5,6 @@ "use strict";

class FlatViewMap extends Map {
onDidSetKey;
set(key, value) {
var _a;
super.set(key, value);
this.onDidSetKey?.(key, value);
(_a = this.onDidSetKey) === null || _a === void 0 ? void 0 : _a.call(this, key, value);
return this;

@@ -11,0 +11,0 @@ }

@@ -5,5 +5,2 @@ "use strict";

class Leaf {
id;
parent;
data;
constructor(id, parent, data) {

@@ -10,0 +7,0 @@ this.id = id;

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -9,14 +18,97 @@ exports.Tree = void 0;

class Tree {
source;
rootBranch;
flatViewMap = new FlatViewMap_1.FlatViewMap();
treeNodeMap = new Map();
pendingLoadChildrenRequests = new Map();
onVisibleNodesChangeCallback = () => void 0;
static isLeaf = (treeNode) => treeNode.constructor === Leaf_1.Leaf;
static isBranch = (treeNode) => treeNode.constructor === Branch_1.Branch;
constructor(source, rootBranchData) {
this.source = source;
this.flatViewMap = new FlatViewMap_1.FlatViewMap();
this.treeNodeMap = new Map();
this.pendingLoadChildrenRequests = new Map();
this.onVisibleNodesChangeCallback = () => void 0;
this.getTreeNodeById = (id) => this.treeNodeMap.get(id);
/**
* Ensures that the children of any given branch have been loaded and ready to be worked with.
*
* Call this method without any arguments to check if the root branch is loaded.
*
* ⚠ "Loaded" doesn't mean expanded, it just means the contents are "ready". Except when no arguments are given, the
* branch being checked is root, and root is always expanded.
*/
this.ensureLoaded = (branch = this.rootBranch) => __awaiter(this, void 0, void 0, function* () {
if (!branch.nodes) {
return this.loadNodes(branch);
}
});
this.expand = (branch, ensureVisible = false, recursive = false) => __awaiter(this, void 0, void 0, function* () {
const isVisibilitySkipable = !ensureVisible || (ensureVisible && this.isVisible(branch));
if (!recursive && this.isTrulyExpanded(branch) && isVisibilitySkipable) {
return;
}
branch.expanded = true;
yield this.ensureLoaded(branch);
// check again as collapse might have been called in the meantime
if (branch.expanded) {
this.connectBranchToClosestFlatView(branch, ensureVisible);
if (recursive) {
yield Promise.all(branch.nodes.map(node => Tree.isBranch(node)
? this.expand(node, ensureVisible, recursive)
: null));
}
}
});
this.collapse = (branch) => {
if (branch.expanded) {
this.disconnectBranchFromClosestFlatView(branch);
}
};
this.amend = (branch, amendFn) => {
let modified = false;
let draftNodes = branch.nodes.slice();
const factory = this.getTreeNodeFactory(branch);
const insertNode = (node, insertionIndex) => {
modified = true;
draftNodes.splice(insertionIndex !== null && insertionIndex !== void 0 ? insertionIndex : Infinity, 0, node);
return node;
};
amendFn({
draftNodes,
insertBranch: (data, insertionIndex) => insertNode(factory.createBranch(data), insertionIndex),
insertLeaf: (data, insertionIndex) => insertNode(factory.createLeaf(data), insertionIndex),
sort: (comparatorFn) => {
modified = true;
draftNodes.sort(comparatorFn);
},
revertChanges: () => {
modified = false;
draftNodes = branch.nodes.slice();
}
});
if (modified) {
this.setNodes(branch, draftNodes);
}
};
this.removeNode = (node) => {
const teardown = (childNode) => {
var _a;
// TODO: dispatch remove event
this.removeNodeFromFlatView(childNode);
this.treeNodeMap.delete(childNode.id);
if (Tree.isBranch(childNode)) {
(_a = childNode.nodes) === null || _a === void 0 ? void 0 : _a.forEach(teardown);
}
};
teardown(node);
const { parent } = node;
parent.nodes = parent.nodes.filter(n => n !== node);
};
this.moveNode = (node, to) => {
};
/**
* A more accurate and real-time representation of whether a branch is expanded.
*
* `Branch#expanded` represents the "intended" expansion state of the branch in question not the actual
* status, because the child nodes might still need to be loaded before the change can be seen in the tree.
*/
this.isTrulyExpanded = (branch) => branch.nodes && branch.expanded && !this.flatViewMap.has(branch.id);
this.isVisible = (node) => !this.findClosestDisconnectedParent(node);
this.nextId = ((genesis = 0) => (() => genesis++))();
this.rootBranch = new Branch_1.Branch(this.nextId(), null, rootBranchData);
this.flatViewMap.onDidSetKey = (key) => key === this.rootBranch.id && this.onVisibleNodesChangeCallback?.();
this.flatViewMap.onDidSetKey = (key) => { var _a; return key === this.rootBranch.id && ((_a = this.onVisibleNodesChangeCallback) === null || _a === void 0 ? void 0 : _a.call(this)); };
this.expand(this.rootBranch);

@@ -33,103 +125,19 @@ }

}
getTreeNodeById = (id) => this.treeNodeMap.get(id);
/**
* Ensures that the children of any given branch have been loaded and ready to be worked with.
*
* Call this method without any arguments to check if the root branch is loaded.
*
* ⚠ "Loaded" doesn't mean expanded, it just means the contents are "ready". Except when no arguments are given, the
* branch being checked is root, and root is always expanded.
*/
ensureLoaded = async (branch = this.rootBranch) => {
if (!branch.nodes) {
return this.loadNodes(branch);
}
};
expand = async (branch, ensureVisible = false, recursive = false) => {
const isVisibilitySkipable = !ensureVisible || (ensureVisible && this.isVisible(branch));
if (!recursive && this.isTrulyExpanded(branch) && isVisibilitySkipable) {
return;
}
branch.expanded = true;
await this.ensureLoaded(branch);
// check again as collapse might have been called in the meantime
if (branch.expanded) {
this.connectBranchToClosestFlatView(branch, ensureVisible);
if (recursive) {
await Promise.all(branch.nodes.map(node => Tree.isBranch(node)
? this.expand(node, ensureVisible, recursive)
: null));
loadNodes(parent) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.pendingLoadChildrenRequests.has(parent)) {
const promise = (() => __awaiter(this, void 0, void 0, function* () {
const nodes = yield this.source.getNodes(parent === this.rootBranch ? null : parent, this.getTreeNodeFactory(parent));
this.setNodes(parent, nodes);
for (const node of nodes) {
if (Tree.isBranch(node) && node.expanded) {
this.expand(node);
}
}
}))();
promise.finally(() => this.pendingLoadChildrenRequests.delete(parent));
this.pendingLoadChildrenRequests.set(parent, promise);
}
}
};
collapse = (branch) => {
if (branch.expanded) {
this.disconnectBranchFromClosestFlatView(branch);
}
};
amend = (branch, amendFn) => {
let modified = false;
let draftNodes = branch.nodes.slice();
const factory = this.getTreeNodeFactory(branch);
const insertNode = (node, insertionIndex) => {
modified = true;
draftNodes.splice(insertionIndex ?? Infinity, 0, node);
return node;
};
amendFn({
draftNodes,
insertBranch: (data, insertionIndex) => insertNode(factory.createBranch(data), insertionIndex),
insertLeaf: (data, insertionIndex) => insertNode(factory.createLeaf(data), insertionIndex),
sort: (comparatorFn) => {
modified = true;
draftNodes.sort(comparatorFn);
},
revertChanges: () => {
modified = false;
draftNodes = branch.nodes.slice();
}
return this.pendingLoadChildrenRequests.get(parent);
});
if (modified) {
this.setNodes(branch, draftNodes);
}
};
removeNode = (node) => {
const teardown = (childNode) => {
// TODO: dispatch remove event
this.removeNodeFromFlatView(childNode);
this.treeNodeMap.delete(childNode.id);
if (Tree.isBranch(childNode)) {
childNode.nodes?.forEach(teardown);
}
};
teardown(node);
const { parent } = node;
parent.nodes = parent.nodes.filter(n => n !== node);
};
moveNode = (node, to) => {
};
/**
* A more accurate and real-time representation of whether a branch is expanded.
*
* `Branch#expanded` represents the "intended" expansion state of the branch in question not the actual
* status, because the child nodes might still need to be loaded before the change can be seen in the tree.
*/
isTrulyExpanded = (branch) => branch.nodes && branch.expanded && !this.flatViewMap.has(branch.id);
isVisible = (node) => !this.findClosestDisconnectedParent(node);
nextId = ((genesis = 0) => (() => genesis++))();
async loadNodes(parent) {
if (!this.pendingLoadChildrenRequests.has(parent)) {
const promise = (async () => {
const nodes = await this.source.getNodes(parent === this.rootBranch ? null : parent, this.getTreeNodeFactory(parent));
this.setNodes(parent, nodes);
for (const node of nodes) {
if (Tree.isBranch(node) && node.expanded) {
this.expand(node);
}
}
})();
promise.finally(() => this.pendingLoadChildrenRequests.delete(parent));
this.pendingLoadChildrenRequests.set(parent, promise);
}
return this.pendingLoadChildrenRequests.get(parent);
}

@@ -245,2 +253,4 @@ setNodes(branch, nodes) {

exports.Tree = Tree;
Tree.isLeaf = (treeNode) => treeNode.constructor === Leaf_1.Leaf;
Tree.isBranch = (treeNode) => treeNode.constructor === Branch_1.Branch;
//# sourceMappingURL=Tree.js.map
{
"name": "aspen-core",
"description": "The most performant virtualized tree driver",
"version": "0.0.1-alpha.0",
"version": "0.0.1-alpha.1",
"keywords": [

@@ -28,3 +28,3 @@ "TODO"

},
"gitHead": "9a0c6b4a24edb08ac32d08bab4f5deaf4da97357"
"gitHead": "8b5ea2d55b4fd68983e27d5988cb90d5269c991d"
}

@@ -6,3 +6,6 @@ {

"declarationDir": "dist/typings"
}
},
"include": [
"src/*"
]
}

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc