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

snabbdom

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snabbdom - npm Package Compare versions

Comparing version 0.3.4 to 0.4.0

htmldomapi.js

2

package.json
{
"name": "snabbdom",
"version": "0.3.4",
"version": "0.4.0",
"description": "A virtual DOM library with focus on simplicity, modularity, powerful features and performance.",

@@ -5,0 +5,0 @@ "main": "snabbdom.js",

@@ -7,2 +7,3 @@ // jshint newcap: false

var is = require('./is');
var domApi = require('./htmldomapi.js');

@@ -12,7 +13,2 @@ function isUndef(s) { return s === undefined; }

// deal with case sensivity better than that
function emptyNodeAt(elm) {
return VNode(elm.tagName.toLowerCase(), {}, [], undefined, elm);
}
var emptyNode = VNode('', {}, [], undefined, undefined);

@@ -33,12 +29,9 @@

function createRmCb(childElm, listeners) {
return function() {
if (--listeners === 0) childElm.parentElement.removeChild(childElm);
};
}
var hooks = ['create', 'update', 'remove', 'destroy', 'pre', 'post'];
function init(modules) {
function init(modules, api) {
var i, j, cbs = {};
if (isUndef(api)) api = domApi;
for (i = 0; i < hooks.length; ++i) {

@@ -51,2 +44,15 @@ cbs[hooks[i]] = [];

function emptyNodeAt(elm) {
return VNode(api.tagName(elm).toLowerCase(), {}, [], undefined, elm);
}
function createRmCb(childElm, listeners) {
return function() {
if (--listeners === 0) {
var parent = api.parentNode(childElm);
api.removeChild(parent, childElm);
}
};
}
function createElm(vnode, insertedVnodeQueue) {

@@ -69,4 +75,4 @@ var i, thunk, data = vnode.data;

var tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel;
elm = vnode.elm = isDef(data) && isDef(i = data.ns) ? document.createElementNS(i, tag)
: document.createElement(tag);
elm = vnode.elm = isDef(data) && isDef(i = data.ns) ? api.createElementNS(i, tag)
: api.createElement(tag);
if (hash < dot) elm.id = sel.slice(hash + 1, dot);

@@ -76,6 +82,6 @@ if (dotIdx > 0) elm.className = sel.slice(dot+1).replace(/\./g, ' ');

for (i = 0; i < children.length; ++i) {
elm.appendChild(createElm(children[i], insertedVnodeQueue));
api.appendChild(elm, createElm(children[i], insertedVnodeQueue));
}
} else if (is.primitive(vnode.text)) {
elm.appendChild(document.createTextNode(vnode.text));
api.appendChild(elm, api.createTextNode(vnode.text));
}

@@ -89,3 +95,3 @@ for (i = 0; i < cbs.create.length; ++i) cbs.create[i](emptyNode, vnode);

} else {
elm = vnode.elm = document.createTextNode(vnode.text);
elm = vnode.elm = api.createTextNode(vnode.text);
}

@@ -98,3 +104,3 @@ if (isDef(thunk)) thunk.elm = vnode.elm;

for (; startIdx <= endIdx; ++startIdx) {
parentElm.insertBefore(createElm(vnodes[startIdx], insertedVnodeQueue), before);
api.insertBefore(parentElm, createElm(vnodes[startIdx], insertedVnodeQueue), before);
}

@@ -132,3 +138,3 @@ }

} else { // Text node
parentElm.removeChild(ch.elm);
api.removeChild(parentElm, ch.elm);
}

@@ -164,3 +170,3 @@ }

patchVnode(oldStartVnode, newEndVnode, insertedVnodeQueue);
parentElm.insertBefore(oldStartVnode.elm, oldEndVnode.elm.nextSibling);
api.insertBefore(parentElm, oldStartVnode.elm, api.nextSibling(oldEndVnode.elm));
oldStartVnode = oldCh[++oldStartIdx];

@@ -170,3 +176,3 @@ newEndVnode = newCh[--newEndIdx];

patchVnode(oldEndVnode, newStartVnode, insertedVnodeQueue);
parentElm.insertBefore(oldEndVnode.elm, oldStartVnode.elm);
api.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm);
oldEndVnode = oldCh[--oldEndIdx];

@@ -178,3 +184,3 @@ newStartVnode = newCh[++newStartIdx];

if (isUndef(idxInOld)) { // New element
parentElm.insertBefore(createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
api.insertBefore(parentElm, createElm(newStartVnode, insertedVnodeQueue), oldStartVnode.elm);
newStartVnode = newCh[++newStartIdx];

@@ -185,3 +191,3 @@ } else {

oldCh[idxInOld] = undefined;
parentElm.insertBefore(elmToMove.elm, oldStartVnode.elm);
api.insertBefore(parentElm, elmToMove.elm, oldStartVnode.elm);
newStartVnode = newCh[++newStartIdx];

@@ -213,5 +219,5 @@ }

if (!sameVnode(oldVnode, vnode)) {
var parentElm = oldVnode.elm.parentElement;
var parentElm = api.parentNode(oldVnode.elm);
elm = createElm(vnode, insertedVnodeQueue);
parentElm.insertBefore(elm, oldVnode.elm);
api.insertBefore(parentElm, elm, oldVnode.elm);
removeVnodes(parentElm, [oldVnode], 0, 0);

@@ -229,3 +235,3 @@ return;

} else if (isDef(ch)) {
if (isDef(oldVnode.text)) elm.textContent = '';
if (isDef(oldVnode.text)) api.setTextContent(elm, '');
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue);

@@ -235,6 +241,6 @@ } else if (isDef(oldCh)) {

} else if (isDef(oldVnode.text)) {
elm.textContent = '';
api.setTextContent(elm, '');
}
} else if (oldVnode.text !== vnode.text) {
elm.textContent = vnode.text;
api.setTextContent(elm, vnode.text);
}

@@ -251,3 +257,3 @@ if (isDef(hook) && isDef(i = hook.postpatch)) {

if (oldVnode.nodeType === Node.ELEMENT_NODE) {
if (isUndef(oldVnode.sel)) {
oldVnode = emptyNodeAt(oldVnode);

@@ -260,3 +266,3 @@ }

elm = oldVnode.elm;
parent = elm.parentElement;
parent = api.parentNode(elm);

@@ -266,3 +272,3 @@ createElm(vnode, insertedVnodeQueue);

if (parent !== null) {
parent.insertBefore(vnode.elm, elm.nextSibling);
api.insertBefore(parent, vnode.elm, api.nextSibling(elm));
removeVnodes(parent, [oldVnode], 0, 0);

@@ -269,0 +275,0 @@ }

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