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

babel-plugin-jsx-dom-expressions

Package Overview
Dependencies
Maintainers
1
Versions
376
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-plugin-jsx-dom-expressions - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

203

dist/createRuntime.js

@@ -5,10 +5,43 @@ const GROUPING = '__recGroup',

function prepNodes(node, id) {
if (node.nodeType === 11) {
let mark = node.firstChild;
while(mark) {
mark[GROUPING] = id;
mark = mark.nextSibling;
}
} else node[GROUPING] = id;
return node;
}
function step(node, direction) {
const key = node[GROUPING];
if (key) {
while(node[direction] && node[direction][GROUPING] === key) node = node[direction];
}
while(node[direction] && node[direction][GROUPING] === key) node = node[direction];
return node[direction];
}
function removeNodes(parent, node, end) {
let tmp;
while(node !== end) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
}
function insertNodes(parent, node, end, target) {
let tmp;
while (node !== end) {
tmp = node.nextSibling;
parent.insertBefore(node, target);
node = tmp;
}
}
function cleanNode(disposables, node) {
const key = node[GROUPING];
disposables.get(key)();
disposables.delete(key);
}
// This is almost straightforward implementation of reconcillation algorithm

@@ -24,20 +57,13 @@ // based on ivi documentation:

const { wrap, cleanup, root, sample } = options;
let disposables = [], counter = 0;
let disposables = new Map(), counter = 0;
function prepNodes(node) {
if (node.nodeType === 11) {
let mark = node.firstChild;
counter++;
while(mark) {
mark[GROUPING] = counter;
mark = mark.nextSibling;
}
}
return node;
function createFn(item, i, afterNode) {
return root(disposer => {
disposables.set(++counter, disposer);
const node = prepNodes(mapFn(item, i), counter);
afterNode ? parent.insertBefore(node, afterNode) : parent.appendChild(node);
return node;
});
}
function createFn(item, i) {
return root(disposer => (disposables[i] = disposer, prepNodes(mapFn(item, i))));
}
function afterRender() {

@@ -49,24 +75,21 @@ afterRenderFn && afterRenderFn(

cleanup(function dispose() { for (let i = 0; i < disposables.length; i++) disposables[i](); });
cleanup(function dispose() {
for (let i of disposables.keys()) disposables.get(i)();
disposables.clear();
});
wrap((renderedValues = []) => {
const data = accessor();
parent = (beforeNode && beforeNode.parentNode) || parent;
return sample(() => {
parent = (beforeNode && beforeNode.parentNode) || parent;
const length = data.length;
// Fast path for clear
const length = data.length;
if (length === 0) {
if (beforeNode !== undefined || afterNode !== undefined) {
let node = beforeNode !== undefined ? beforeNode.nextSibling : parent.firstChild,
newAfterNode = afterNode, tmp;
let node = beforeNode !== undefined ? beforeNode.nextSibling : parent.firstChild;
removeNodes(parent, node, afterNode === undefined ? null : afterNode);
} else parent.textContent = "";
if (newAfterNode === undefined) newAfterNode = null;
while(node !== newAfterNode) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
} else parent.textContent = "";
for (let i = 0; i < renderedValues.length; i++) disposables[i]();
disposables = [];
for (let i of disposables.keys()) disposables.get(i)();
disposables.clear();
afterRender();

@@ -78,7 +101,4 @@ return [];

if (renderedValues.length === 0) {
let node, mode = (afterNode !== undefined), nextData = new Array(length);
for (let i = 0; i < length; i++) {
node = createFn(nextData[i] = data[i], i);
mode ? parent.insertBefore(node, afterNode) : parent.appendChild(node);
}
let nextData = new Array(length);
for (let i = 0; i < length; i++) createFn(nextData[i] = data[i], i, afterNode);
afterRender();

@@ -105,3 +125,2 @@ return nextData;

while(a === b) {
disposables[newStart] = disposables[prevStart];
prevStart++;

@@ -118,3 +137,2 @@ newStart++;

while(a === b) {
disposables[newEnd] = disposables[prevEnd];
prevEnd--;

@@ -136,10 +154,4 @@ newEnd--;

if (newStartNode !== mark) {
while (mark !== prevEndNode) {
let tmp = mark.nextSibling;
parent.insertBefore(mark, newStartNode);
mark = tmp;
}
parent.insertBefore(mark, newStartNode);
insertNodes(parent, mark, prevEndNode.nextSibling, newStartNode);
prevEndNode = _node;
disposables.splice(newStart, 0, disposables.splice(prevEnd, 1)[0]);
}

@@ -158,11 +170,5 @@ newStart++;

_node = step(prevStartNode, FORWARD);
let mark = prevStartNode, tmp;
if (mark !== newAfterNode) {
while (mark.nextSibling !== _node) {
tmp = mark.nextSibling;
parent.insertBefore(mark, newAfterNode);
mark = tmp;
}
parent.insertBefore(mark, newAfterNode);
disposables.splice(newEnd, 0, disposables.splice(prevStart, 1)[0]);
if (prevStartNode !== newAfterNode) {
let mark = _node.previousSibling;
insertNodes(parent, prevStartNode, _node, newAfterNode);
newAfterNode = mark;

@@ -182,17 +188,11 @@ prevStartNode = _node;

if (prevStart <= prevEnd) {
let next, mark, tmp;
let next;
while(prevStart <= prevEnd) {
next = step(prevEndNode, BACKWARD);
mark = prevEndNode;
while (mark !== next) {
tmp = mark.previousSibling;
parent.removeChild(mark);
mark = tmp;
}
removeNodes(parent, next.nextSibling, prevEndNode.nextSibling);
cleanNode(disposables, prevEndNode);
prevEndNode = next;
disposables[prevEnd]();
prevEnd--;
}
}
disposables.length = length;
afterRender();

@@ -205,6 +205,4 @@ return data.slice(0);

if (newStart <= newEnd) {
let node, mode = newAfterNode ? 1 : 0;
while(newStart <= newEnd) {
node = createFn(data[newStart], newStart);
mode ? parent.insertBefore(node, newAfterNode) : parent.appendChild(node);
createFn(data[newStart], newStart, newAfterNode);
newStart++;

@@ -237,29 +235,15 @@ }

if (reusingNodes === 0) {
if (prevStartNode !== parent.firstChild || prevEndNode !== parent.lastChild) {
let node = prevStartNode, tmp, mark;
newAfterNode = prevEndNode.nextSibling;
while(node !== newAfterNode) {
mark = step(node, FORWARD);
while (node !== mark) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
disposables[prevStart]();
prevStart++;
}
} else {
while(prevStart <= prevEnd) {
disposables[prevStart]();
prevStart++;
}
parent.textContent = "";
const doRemove = prevStartNode !== parent.firstChild || prevEndNode !== parent.lastChild;
let node = prevStartNode, mark;
newAfterNode = prevEndNode.nextSibling;
while(node !== newAfterNode) {
mark = step(node, FORWARD);
cleanNode(disposables, node);
doRemove && removeNodes(parent, node, mark);
node = mark;
prevStart++;
}
!doRemove && (parent.textContent = "");
let node, mode = newAfterNode ? 1 : 0;
for(let i = newStart; i <= newEnd; i++) {
node = createFn(data[i], i);
mode ? parent.insertBefore(node, newAfterNode) : parent.appendChild(node);
}
for(let i = newStart; i <= newEnd; i++) createFn(data[i], i, newAfterNode);
afterRender();

@@ -270,7 +254,7 @@ return data.slice(0);

// What else?
const longestSeq = longestPositiveIncreasingSubsequence(P, newStart);
const longestSeq = longestPositiveIncreasingSubsequence(P, newStart),
nodes = [];
let tmpC = prevStartNode, lisIdx = longestSeq.length - 1, tmpD;
// Collect nodes to work with them
const nodes = [];
let tmpC = prevStartNode;
for(let i = prevStart; i <= prevEnd; i++) {

@@ -282,32 +266,18 @@ nodes[i] = tmpC;

for(let i = 0; i < toRemove.length; i++) {
const index = toRemove[i];
let node = nodes[index], end = step(node, FORWARD), tmp;
while(node !== end) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
disposables[index]();
let index = toRemove[i],
node = nodes[index];
removeNodes(parent, node, step(node, FORWARD));
cleanNode(disposables, node);
}
const oldDisposables = disposables.slice(0);
let lisIdx = longestSeq.length - 1, tmpD;
for(let i = newEnd; i >= newStart; i--) {
if(longestSeq[lisIdx] === i) {
newAfterNode = nodes[P[longestSeq[lisIdx]]];
disposables[i] = oldDisposables[P[i]];
lisIdx--;
} else {
if (P[i] === -1) {
tmpD = createFn(data[i], i);
parent.insertBefore(tmpD, newAfterNode);
tmpD = createFn(data[i], i, newAfterNode);
} else {
disposables[i] = oldDisposables[P[i]];
tmpD = nodes[P[i]];
let mark = tmpD, end = step(mark, FORWARD), tmp;
while (mark !== end) {
tmp = mark.nextSibling;
parent.insertBefore(mark, newAfterNode);
mark = tmp;
}
insertNodes(parent, tmpD, step(tmpD, FORWARD), newAfterNode);
}

@@ -318,3 +288,2 @@ newAfterNode = tmpD;

disposables.length = length;
afterRender();

@@ -321,0 +290,0 @@ return data.slice(0);

@@ -9,10 +9,43 @@ 'use strict';

function prepNodes(node, id) {
if (node.nodeType === 11) {
let mark = node.firstChild;
while(mark) {
mark[GROUPING] = id;
mark = mark.nextSibling;
}
} else node[GROUPING] = id;
return node;
}
function step(node, direction) {
const key = node[GROUPING];
if (key) {
while(node[direction] && node[direction][GROUPING] === key) node = node[direction];
}
while(node[direction] && node[direction][GROUPING] === key) node = node[direction];
return node[direction];
}
function removeNodes(parent, node, end) {
let tmp;
while(node !== end) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
}
function insertNodes(parent, node, end, target) {
let tmp;
while (node !== end) {
tmp = node.nextSibling;
parent.insertBefore(node, target);
node = tmp;
}
}
function cleanNode(disposables, node) {
const key = node[GROUPING];
disposables.get(key)();
disposables.delete(key);
}
// This is almost straightforward implementation of reconcillation algorithm

@@ -28,20 +61,13 @@ // based on ivi documentation:

const { wrap, cleanup, root, sample } = options;
let disposables = [], counter = 0;
let disposables = new Map(), counter = 0;
function prepNodes(node) {
if (node.nodeType === 11) {
let mark = node.firstChild;
counter++;
while(mark) {
mark[GROUPING] = counter;
mark = mark.nextSibling;
}
}
return node;
function createFn(item, i, afterNode) {
return root(disposer => {
disposables.set(++counter, disposer);
const node = prepNodes(mapFn(item, i), counter);
afterNode ? parent.insertBefore(node, afterNode) : parent.appendChild(node);
return node;
});
}
function createFn(item, i) {
return root(disposer => (disposables[i] = disposer, prepNodes(mapFn(item, i))));
}
function afterRender() {

@@ -53,24 +79,21 @@ afterRenderFn && afterRenderFn(

cleanup(function dispose() { for (let i = 0; i < disposables.length; i++) disposables[i](); });
cleanup(function dispose() {
for (let i of disposables.keys()) disposables.get(i)();
disposables.clear();
});
wrap((renderedValues = []) => {
const data = accessor();
parent = (beforeNode && beforeNode.parentNode) || parent;
return sample(() => {
parent = (beforeNode && beforeNode.parentNode) || parent;
const length = data.length;
// Fast path for clear
const length = data.length;
if (length === 0) {
if (beforeNode !== undefined || afterNode !== undefined) {
let node = beforeNode !== undefined ? beforeNode.nextSibling : parent.firstChild,
newAfterNode = afterNode, tmp;
let node = beforeNode !== undefined ? beforeNode.nextSibling : parent.firstChild;
removeNodes(parent, node, afterNode === undefined ? null : afterNode);
} else parent.textContent = "";
if (newAfterNode === undefined) newAfterNode = null;
while(node !== newAfterNode) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
} else parent.textContent = "";
for (let i = 0; i < renderedValues.length; i++) disposables[i]();
disposables = [];
for (let i of disposables.keys()) disposables.get(i)();
disposables.clear();
afterRender();

@@ -82,7 +105,4 @@ return [];

if (renderedValues.length === 0) {
let node, mode = (afterNode !== undefined), nextData = new Array(length);
for (let i = 0; i < length; i++) {
node = createFn(nextData[i] = data[i], i);
mode ? parent.insertBefore(node, afterNode) : parent.appendChild(node);
}
let nextData = new Array(length);
for (let i = 0; i < length; i++) createFn(nextData[i] = data[i], i, afterNode);
afterRender();

@@ -109,3 +129,2 @@ return nextData;

while(a === b) {
disposables[newStart] = disposables[prevStart];
prevStart++;

@@ -122,3 +141,2 @@ newStart++;

while(a === b) {
disposables[newEnd] = disposables[prevEnd];
prevEnd--;

@@ -140,10 +158,4 @@ newEnd--;

if (newStartNode !== mark) {
while (mark !== prevEndNode) {
let tmp = mark.nextSibling;
parent.insertBefore(mark, newStartNode);
mark = tmp;
}
parent.insertBefore(mark, newStartNode);
insertNodes(parent, mark, prevEndNode.nextSibling, newStartNode);
prevEndNode = _node;
disposables.splice(newStart, 0, disposables.splice(prevEnd, 1)[0]);
}

@@ -162,11 +174,5 @@ newStart++;

_node = step(prevStartNode, FORWARD);
let mark = prevStartNode, tmp;
if (mark !== newAfterNode) {
while (mark.nextSibling !== _node) {
tmp = mark.nextSibling;
parent.insertBefore(mark, newAfterNode);
mark = tmp;
}
parent.insertBefore(mark, newAfterNode);
disposables.splice(newEnd, 0, disposables.splice(prevStart, 1)[0]);
if (prevStartNode !== newAfterNode) {
let mark = _node.previousSibling;
insertNodes(parent, prevStartNode, _node, newAfterNode);
newAfterNode = mark;

@@ -186,17 +192,11 @@ prevStartNode = _node;

if (prevStart <= prevEnd) {
let next, mark, tmp;
let next;
while(prevStart <= prevEnd) {
next = step(prevEndNode, BACKWARD);
mark = prevEndNode;
while (mark !== next) {
tmp = mark.previousSibling;
parent.removeChild(mark);
mark = tmp;
}
removeNodes(parent, next.nextSibling, prevEndNode.nextSibling);
cleanNode(disposables, prevEndNode);
prevEndNode = next;
disposables[prevEnd]();
prevEnd--;
}
}
disposables.length = length;
afterRender();

@@ -209,6 +209,4 @@ return data.slice(0);

if (newStart <= newEnd) {
let node, mode = newAfterNode ? 1 : 0;
while(newStart <= newEnd) {
node = createFn(data[newStart], newStart);
mode ? parent.insertBefore(node, newAfterNode) : parent.appendChild(node);
createFn(data[newStart], newStart, newAfterNode);
newStart++;

@@ -241,29 +239,15 @@ }

if (reusingNodes === 0) {
if (prevStartNode !== parent.firstChild || prevEndNode !== parent.lastChild) {
let node = prevStartNode, tmp, mark;
newAfterNode = prevEndNode.nextSibling;
while(node !== newAfterNode) {
mark = step(node, FORWARD);
while (node !== mark) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
disposables[prevStart]();
prevStart++;
}
} else {
while(prevStart <= prevEnd) {
disposables[prevStart]();
prevStart++;
}
parent.textContent = "";
const doRemove = prevStartNode !== parent.firstChild || prevEndNode !== parent.lastChild;
let node = prevStartNode, mark;
newAfterNode = prevEndNode.nextSibling;
while(node !== newAfterNode) {
mark = step(node, FORWARD);
cleanNode(disposables, node);
doRemove && removeNodes(parent, node, mark);
node = mark;
prevStart++;
}
!doRemove && (parent.textContent = "");
let node, mode = newAfterNode ? 1 : 0;
for(let i = newStart; i <= newEnd; i++) {
node = createFn(data[i], i);
mode ? parent.insertBefore(node, newAfterNode) : parent.appendChild(node);
}
for(let i = newStart; i <= newEnd; i++) createFn(data[i], i, newAfterNode);
afterRender();

@@ -274,7 +258,7 @@ return data.slice(0);

// What else?
const longestSeq = longestPositiveIncreasingSubsequence(P, newStart);
const longestSeq = longestPositiveIncreasingSubsequence(P, newStart),
nodes = [];
let tmpC = prevStartNode, lisIdx = longestSeq.length - 1, tmpD;
// Collect nodes to work with them
const nodes = [];
let tmpC = prevStartNode;
for(let i = prevStart; i <= prevEnd; i++) {

@@ -286,32 +270,18 @@ nodes[i] = tmpC;

for(let i = 0; i < toRemove.length; i++) {
const index = toRemove[i];
let node = nodes[index], end = step(node, FORWARD), tmp;
while(node !== end) {
tmp = node.nextSibling;
parent.removeChild(node);
node = tmp;
}
disposables[index]();
let index = toRemove[i],
node = nodes[index];
removeNodes(parent, node, step(node, FORWARD));
cleanNode(disposables, node);
}
const oldDisposables = disposables.slice(0);
let lisIdx = longestSeq.length - 1, tmpD;
for(let i = newEnd; i >= newStart; i--) {
if(longestSeq[lisIdx] === i) {
newAfterNode = nodes[P[longestSeq[lisIdx]]];
disposables[i] = oldDisposables[P[i]];
lisIdx--;
} else {
if (P[i] === -1) {
tmpD = createFn(data[i], i);
parent.insertBefore(tmpD, newAfterNode);
tmpD = createFn(data[i], i, newAfterNode);
} else {
disposables[i] = oldDisposables[P[i]];
tmpD = nodes[P[i]];
let mark = tmpD, end = step(mark, FORWARD), tmp;
while (mark !== end) {
tmp = mark.nextSibling;
parent.insertBefore(mark, newAfterNode);
mark = tmp;
}
insertNodes(parent, tmpD, step(tmpD, FORWARD), newAfterNode);
}

@@ -322,3 +292,2 @@ newAfterNode = tmpD;

disposables.length = length;
afterRender();

@@ -325,0 +294,0 @@ return data.slice(0);

{
"name": "babel-plugin-jsx-dom-expressions",
"description": "A JSX to DOM plugin that wraps expressions for fine grained change detection",
"version": "0.3.3",
"version": "0.3.4",
"author": "Ryan Carniato",

@@ -6,0 +6,0 @@ "license": "MIT",

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