Socket
Socket
Sign inDemoInstall

forgo-state

Package Overview
Dependencies
Maintainers
1
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

forgo-state - npm Package Compare versions

Comparing version 0.0.11 to 0.0.12

46

dist/index.js

@@ -45,8 +45,30 @@ "use strict";

if (args.element.node) {
let entry = argsListMap.get(args.element.node);
if (!entry) {
entry = [];
argsListMap.set(args.element.node, entry);
const state = forgo_1.getForgoState(args.element.node);
if (state) {
const componentState = state.components[args.element.componentIndex];
if (componentState.numNodes === 1) {
let entry = argsListMap.get(args.element.node);
if (!entry) {
entry = [];
argsListMap.set(args.element.node, entry);
}
entry.push(args);
}
// This component rendered a fragment or an array
else {
const parentElement = args.element.node
.parentElement;
const childNodes = Array.from(parentElement.childNodes);
const nodeIndex = childNodes.findIndex((x) => x === args.element.node);
const nodes = childNodes.slice(nodeIndex, nodeIndex + componentState.numNodes);
for (const node of nodes) {
let entry = argsListMap.get(node);
if (!entry) {
entry = [];
argsListMap.set(node, entry);
}
entry.push(args);
}
}
}
entry.push(args);
}

@@ -73,13 +95,15 @@ }

if (argsWithMinComponentIndex) {
argsListWithMinComponentIndex.push(argsWithMinComponentIndex);
argsListWithMinComponentIndex.push([node, argsWithMinComponentIndex]);
}
}
// Now we gotta find if a node is a child of another node pending rerender
// If so, there's no need to render the descendant node.
// 1. We gotta find if a node is a child of another node pending rerender
// If so, there's no need to render the descendant node.
// 2. Also, if a component renders multiple nodes, include only the root node.
const justTheNodes = argsListWithMinComponentIndex
.map((x) => x.element.node)
.map(([node]) => node)
.filter((x) => x);
const argsListOfParentNodes = argsListWithMinComponentIndex.filter((arg) => !justTheNodes.some((node) => node !== arg.element.node && node.contains(arg.element.node)));
const argsListOfParentNodes = argsListWithMinComponentIndex.filter(([node, args]) => !justTheNodes.some((x) => x !== node && x.contains(node)) &&
node === args.element.node);
argsToRenderInTheNextCycle.length = 0;
for (const args of argsListOfParentNodes) {
for (const [node, args] of argsListOfParentNodes) {
argsToRenderInTheNextCycle.push(args);

@@ -86,0 +110,0 @@ }

{
"name": "forgo-state",
"version": "0.0.11",
"version": "0.0.12",
"main": "./dist",

@@ -11,3 +11,3 @@ "author": "Jeswin Kumar<jeswinpk@agilehead.com>",

"dependencies": {
"forgo": "^0.0.35"
"forgo": "^0.0.36"
},

@@ -14,0 +14,0 @@ "devDependencies": {

@@ -6,2 +6,3 @@ import {

rerender,
getForgoState,
} from "forgo";

@@ -77,8 +78,36 @@

if (args.element.node) {
let entry = argsListMap.get(args.element.node);
if (!entry) {
entry = [];
argsListMap.set(args.element.node, entry);
const state = getForgoState(args.element.node);
if (state) {
const componentState =
state.components[args.element.componentIndex];
if (componentState.numNodes === 1) {
let entry = argsListMap.get(args.element.node);
if (!entry) {
entry = [];
argsListMap.set(args.element.node, entry);
}
entry.push(args);
}
// This component rendered a fragment or an array
else {
const parentElement: HTMLElement = args.element.node
.parentElement as HTMLElement;
const childNodes = Array.from(parentElement.childNodes);
const nodeIndex = childNodes.findIndex(
(x) => x === args.element.node
);
const nodes = childNodes.slice(
nodeIndex,
nodeIndex + componentState.numNodes
);
for (const node of nodes) {
let entry = argsListMap.get(node);
if (!entry) {
entry = [];
argsListMap.set(node, entry);
}
entry.push(args);
}
}
}
entry.push(args);
}

@@ -90,3 +119,3 @@ }

// The higher up components get rendered automatically.
const argsListWithMinComponentIndex: ForgoRenderArgs[] = [];
const argsListWithMinComponentIndex: [ChildNode, ForgoRenderArgs][] = [];

@@ -109,22 +138,21 @@ for (const entries of argsListMap) {

if (argsWithMinComponentIndex) {
argsListWithMinComponentIndex.push(argsWithMinComponentIndex);
argsListWithMinComponentIndex.push([node, argsWithMinComponentIndex]);
}
}
// Now we gotta find if a node is a child of another node pending rerender
// If so, there's no need to render the descendant node.
// 1. We gotta find if a node is a child of another node pending rerender
// If so, there's no need to render the descendant node.
// 2. Also, if a component renders multiple nodes, include only the root node.
const justTheNodes = argsListWithMinComponentIndex
.map((x) => x.element.node)
.map(([node]) => node)
.filter((x) => x) as ChildNode[];
const argsListOfParentNodes = argsListWithMinComponentIndex.filter(
(arg) =>
!justTheNodes.some(
(node) =>
node !== arg.element.node && node.contains(arg.element.node as ChildNode)
)
([node, args]) =>
!justTheNodes.some((x) => x !== node && x.contains(node)) &&
node === args.element.node
);
argsToRenderInTheNextCycle.length = 0;
for (const args of argsListOfParentNodes) {
for (const [node, args] of argsListOfParentNodes) {
argsToRenderInTheNextCycle.push(args);

@@ -131,0 +159,0 @@ }

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