typed-dom
Advanced tools
Comparing version 0.0.254 to 0.0.255
@@ -1,2 +0,2 @@ | ||
/*! typed-dom v0.0.254 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
/*! typed-dom v0.0.255 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */ | ||
require = function () { | ||
@@ -720,13 +720,13 @@ function r(e, n, t) { | ||
(function (privates) { | ||
privates.id = Symbol(); | ||
privates.id_ = Symbol(); | ||
privates.query = Symbol(); | ||
privates.query_ = Symbol(); | ||
privates.scope = Symbol(); | ||
privates.observe = Symbol(); | ||
privates.type = Symbol(); | ||
privates.container = Symbol(); | ||
privates.children = Symbol(); | ||
privates.isInit = Symbol(); | ||
privates.isObserverUpdate = Symbol(); | ||
privates.id = Symbol('id'); | ||
privates.id_ = Symbol('id_'); | ||
privates.query = Symbol('query'); | ||
privates.query_ = Symbol('query_'); | ||
privates.scope = Symbol('scope'); | ||
privates.observe = Symbol('observe'); | ||
privates.type = Symbol('type'); | ||
privates.container = Symbol('container'); | ||
privates.children = Symbol('children'); | ||
privates.isInit = Symbol('isInit'); | ||
privates.isObserverUpdate = Symbol('isObserverUpdate'); | ||
}(privates || (privates = {}))); | ||
@@ -856,2 +856,4 @@ let id = (0, identity_1.identity)(); | ||
set children(children) { | ||
const container = this[privates.container]; | ||
const isInit = this[privates.isInit]; | ||
const removedChildren = []; | ||
@@ -866,6 +868,6 @@ const addedChildren = []; | ||
const oldText = this.children; | ||
if (!this[privates.isInit] && newText === oldText) | ||
if (!isInit && newText === oldText) | ||
return; | ||
isMutated = true; | ||
this[privates.container].textContent = newText; | ||
container.textContent = newText; | ||
break; | ||
@@ -881,4 +883,4 @@ } | ||
isMutated || (isMutated = newChild.element !== oldChild.element); | ||
throwErrorIfNotUsable(newChild, this[privates.container]); | ||
if (newChild.element.parentNode !== this[privates.container]) { | ||
throwErrorIfNotUsable(newChild, container); | ||
if (newChild.element.parentNode !== container) { | ||
this[privates.scope](newChild); | ||
@@ -888,7 +890,7 @@ addedChildren.push(newChild); | ||
} | ||
this[privates.container].replaceChildren(...sourceChildren.map(c => c.element)); | ||
container.replaceChildren(...sourceChildren.map(c => c.element)); | ||
this[privates.children] = children; | ||
for (let i = 0; i < targetChildren.length; ++i) { | ||
const oldChild = targetChildren[i]; | ||
if (oldChild.element.parentNode !== this[privates.container]) { | ||
if (oldChild.element.parentNode !== container) { | ||
removedChildren.push(oldChild); | ||
@@ -903,2 +905,4 @@ } | ||
for (const name of (0, alias_1.ObjectKeys)(sourceChildren)) { | ||
if (name in {}) | ||
continue; | ||
const newChild = sourceChildren[name]; | ||
@@ -908,20 +912,20 @@ const oldChild = targetChildren[name]; | ||
continue; | ||
if (!this[privates.isInit] && newChild === oldChild) | ||
if (!isInit && newChild === oldChild) | ||
continue; | ||
isMutated = true; | ||
throwErrorIfNotUsable(newChild, this[privates.container]); | ||
if (this[privates.isInit] || newChild !== oldChild && newChild.element.parentNode !== oldChild.element.parentNode) { | ||
throwErrorIfNotUsable(newChild, container); | ||
if (isInit || newChild !== oldChild && newChild.element.parentNode !== oldChild.element.parentNode) { | ||
this[privates.scope](newChild); | ||
addedChildren.push(newChild); | ||
if (this[privates.isInit]) { | ||
this[privates.container].appendChild(newChild.element); | ||
if (isInit) { | ||
container.appendChild(newChild.element); | ||
} else { | ||
this[privates.container].insertBefore(newChild.element, oldChild.element); | ||
this[privates.container].removeChild(oldChild.element); | ||
container.insertBefore(newChild.element, oldChild.element); | ||
container.removeChild(oldChild.element); | ||
removedChildren.push(oldChild); | ||
} | ||
} else { | ||
const ref = newChild.element.nextSibling !== oldChild.element ? newChild.element.nextSibling : oldChild.element.nextSibling; | ||
this[privates.container].replaceChild(newChild.element, oldChild.element); | ||
this[privates.container].insertBefore(oldChild.element, ref); | ||
const ref = newChild.element.nextSibling; | ||
container.insertBefore(newChild.element, oldChild.element); | ||
container.insertBefore(oldChild.element, ref); | ||
} | ||
@@ -936,17 +940,15 @@ this[privates.isObserverUpdate] = true; | ||
if (removedChildren.length) { | ||
const ev = new global_1.Event('disconnect', { | ||
bubbles: false, | ||
cancelable: true | ||
}); | ||
for (const {element} of removedChildren) { | ||
element.dispatchEvent(ev); | ||
for (const child of removedChildren) { | ||
child.element.dispatchEvent(new global_1.Event('disconnect', { | ||
bubbles: false, | ||
cancelable: true | ||
})); | ||
} | ||
} | ||
if (addedChildren.length) { | ||
const ev = new global_1.Event('connect', { | ||
bubbles: false, | ||
cancelable: true | ||
}); | ||
for (const {element} of addedChildren) { | ||
element.dispatchEvent(ev); | ||
for (const child of addedChildren) { | ||
child.element.dispatchEvent(new global_1.Event('connect', { | ||
bubbles: false, | ||
cancelable: true | ||
})); | ||
} | ||
@@ -953,0 +955,0 @@ } |
{ | ||
"name": "typed-dom", | ||
"version": "0.0.254", | ||
"version": "0.0.255", | ||
"description": "A DOM component builder creating type-level DOM structures.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -335,3 +335,3 @@ # typed-dom | ||
i18n.init((err, t) => | ||
proxy<string>(ev.target as HTMLElement)!.children = err | ||
(ev.target as HTMLElement).textContent = err | ||
? 'Failed to init i18next.' | ||
@@ -338,0 +338,0 @@ : t(children, data)) |
@@ -37,13 +37,13 @@ import { WeakMap, Event } from 'spica/global'; | ||
namespace privates { | ||
export const id = Symbol(); | ||
export const id_ = Symbol(); | ||
export const query = Symbol(); | ||
export const query_ = Symbol(); | ||
export const scope = Symbol(); | ||
export const observe = Symbol(); | ||
export const type = Symbol(); | ||
export const container = Symbol(); | ||
export const children = Symbol(); | ||
export const isInit = Symbol(); | ||
export const isObserverUpdate = Symbol(); | ||
export const id = Symbol('id'); | ||
export const id_ = Symbol('id_'); | ||
export const query = Symbol('query'); | ||
export const query_ = Symbol('query_'); | ||
export const scope = Symbol('scope'); | ||
export const observe = Symbol('observe'); | ||
export const type = Symbol('type'); | ||
export const container = Symbol('container'); | ||
export const children = Symbol('children'); | ||
export const isInit = Symbol('isInit'); | ||
export const isObserverUpdate = Symbol('isObserverUpdate'); | ||
} | ||
@@ -184,2 +184,4 @@ | ||
assert(!this[privates.isObserverUpdate]); | ||
const container = this[privates.container]; | ||
const isInit = this[privates.isInit]; | ||
const removedChildren: El[] = []; | ||
@@ -194,5 +196,5 @@ const addedChildren: El[] = []; | ||
const oldText = this.children; | ||
if (!this[privates.isInit] && newText === oldText) return; | ||
if (!isInit && newText === oldText) return; | ||
isMutated = true; | ||
this[privates.container].textContent = newText as El.Children.Text; | ||
container.textContent = newText as El.Children.Text; | ||
break; | ||
@@ -208,4 +210,4 @@ } | ||
isMutated ||= newChild.element !== oldChild.element; | ||
throwErrorIfNotUsable(newChild, this[privates.container]); | ||
if (newChild.element.parentNode !== this[privates.container]) { | ||
throwErrorIfNotUsable(newChild, container); | ||
if (newChild.element.parentNode !== container) { | ||
this[privates.scope](newChild); | ||
@@ -216,7 +218,7 @@ assert(!addedChildren.includes(newChild)); | ||
} | ||
this[privates.container].replaceChildren(...sourceChildren.map(c => c.element)); | ||
container.replaceChildren(...sourceChildren.map(c => c.element)); | ||
this[privates.children] = children; | ||
for (let i = 0; i < targetChildren.length; ++i) { | ||
const oldChild = targetChildren[i]; | ||
if (oldChild.element.parentNode !== this[privates.container]) { | ||
if (oldChild.element.parentNode !== container) { | ||
assert(!removedChildren.includes(oldChild)); | ||
@@ -227,4 +229,4 @@ removedChildren.push(oldChild); | ||
} | ||
assert(this[privates.container].children.length === sourceChildren.length); | ||
assert(sourceChildren.every((child, i) => child.element === this[privates.container].children[i])); | ||
assert(container.children.length === sourceChildren.length); | ||
assert(sourceChildren.every((child, i) => child.element === container.children[i])); | ||
break; | ||
@@ -236,18 +238,19 @@ } | ||
for (const name of ObjectKeys(sourceChildren)) { | ||
if (name in {}) continue; | ||
const newChild = sourceChildren[name]; | ||
const oldChild = targetChildren[name]; | ||
if (!newChild || !oldChild) continue; | ||
if (!this[privates.isInit] && newChild === oldChild) continue; | ||
if (!isInit && newChild === oldChild) continue; | ||
isMutated = true; | ||
throwErrorIfNotUsable(newChild, this[privates.container]); | ||
if (this[privates.isInit] || newChild !== oldChild && newChild.element.parentNode !== oldChild.element.parentNode) { | ||
throwErrorIfNotUsable(newChild, container); | ||
if (isInit || newChild !== oldChild && newChild.element.parentNode !== oldChild.element.parentNode) { | ||
this[privates.scope](newChild); | ||
assert(!addedChildren.includes(newChild)); | ||
addedChildren.push(newChild); | ||
if (this[privates.isInit]) { | ||
this[privates.container].appendChild(newChild.element); | ||
if (isInit) { | ||
container.appendChild(newChild.element); | ||
} | ||
else { | ||
this[privates.container].insertBefore(newChild.element, oldChild.element); | ||
this[privates.container].removeChild(oldChild.element); | ||
container.insertBefore(newChild.element, oldChild.element); | ||
container.removeChild(oldChild.element); | ||
assert(!removedChildren.includes(oldChild)); | ||
@@ -259,7 +262,5 @@ removedChildren.push(oldChild); | ||
assert(newChild.element.parentNode === oldChild.element.parentNode); | ||
const ref = newChild.element.nextSibling !== oldChild.element | ||
? newChild.element.nextSibling | ||
: oldChild.element.nextSibling; | ||
this[privates.container].replaceChild(newChild.element, oldChild.element); | ||
this[privates.container].insertBefore(oldChild.element, ref); | ||
const ref = newChild.element.nextSibling; | ||
container.insertBefore(newChild.element, oldChild.element); | ||
container.insertBefore(oldChild.element, ref); | ||
} | ||
@@ -275,11 +276,9 @@ this[privates.isObserverUpdate] = true; | ||
if (removedChildren.length) { | ||
const ev = new Event('disconnect', { bubbles: false, cancelable: true }); | ||
for (const { element } of removedChildren) { | ||
element.dispatchEvent(ev); | ||
for (const child of removedChildren) { | ||
child.element.dispatchEvent(new Event('disconnect', { bubbles: false, cancelable: true })); | ||
} | ||
} | ||
if (addedChildren.length) { | ||
const ev = new Event('connect', { bubbles: false, cancelable: true }); | ||
for (const { element } of addedChildren) { | ||
element.dispatchEvent(ev); | ||
for (const child of addedChildren) { | ||
child.element.dispatchEvent(new Event('connect', { bubbles: false, cancelable: true })); | ||
} | ||
@@ -286,0 +285,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Shadow, HTML, SVG, API, El, proxy, shadow, frag, html } from '../../index'; | ||
import { Shadow, HTML, SVG, API, El, shadow, html } from '../../index'; | ||
import { Coroutine } from 'spica/coroutine'; | ||
@@ -320,7 +320,6 @@ import { Sequence } from 'spica/sequence'; | ||
it('swap', function () { | ||
assert.throws(() => HTML.article(HTML.article([HTML.p()]).children)); | ||
const el = HTML.article([HTML.p()]); | ||
const children = el.children; | ||
assert.throws(() => HTML.article(children)); | ||
el.children = [HTML.p()]; | ||
frag(children.map(el => el.element)); | ||
assert(HTML.article(children)); | ||
@@ -549,3 +548,3 @@ }); | ||
i18n.init((err, t) => | ||
proxy<string>(ev.target as HTMLElement)!.children = err | ||
(ev.target as HTMLElement).textContent = err | ||
? 'Failed to init i18next.' | ||
@@ -552,0 +551,0 @@ : t(children, data)) |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
653963