@thi.ng/hdom
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -6,2 +6,13 @@ # Change Log | ||
<a name="3.0.1"></a> | ||
## [3.0.1](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom@3.0.0...@thi.ng/hdom@3.0.1) (2018-04-09) | ||
### Performance Improvements | ||
* **hdom:** intern imported checks, update normalizeTree(), add docs, fix tests ([2a91e30](https://github.com/thi-ng/umbrella/commit/2a91e30)) | ||
<a name="3.0.0"></a> | ||
@@ -8,0 +19,0 @@ # [3.0.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/hdom@2.3.3...@thi.ng/hdom@3.0.0) (2018-04-08) |
18
diff.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_array_1 = require("@thi.ng/checks/is-array"); | ||
const is_string_1 = require("@thi.ng/checks/is-string"); | ||
const isa = require("@thi.ng/checks/is-array"); | ||
const iss = require("@thi.ng/checks/is-string"); | ||
const diff = require("@thi.ng/diff"); | ||
// import { DEBUG } from "./api"; | ||
const dom_1 = require("./dom"); | ||
const isArray = isa.isArray; | ||
const isString = iss.isString; | ||
const diffArray = diff.diffArray; | ||
@@ -69,3 +71,3 @@ const diffObject = diff.diffObject; | ||
if (status === -1) { | ||
if (is_array_1.isArray(val)) { | ||
if (isArray(val)) { | ||
k = val[1].key; | ||
@@ -88,3 +90,3 @@ if (k !== undefined && equivKeys[k][2] !== undefined) { | ||
} | ||
else if (is_string_1.isString(val)) { | ||
else if (isString(val)) { | ||
el.textContent = ""; | ||
@@ -94,6 +96,6 @@ } | ||
else if (status === 1) { | ||
if (is_string_1.isString(val)) { | ||
if (isString(val)) { | ||
el.textContent = val; | ||
} | ||
else if (is_array_1.isArray(val)) { | ||
else if (isArray(val)) { | ||
k = val[1].key; | ||
@@ -113,3 +115,3 @@ if (k === undefined || (k && equivKeys[k][0] === undefined)) { | ||
function releaseDeep(tag) { | ||
if (is_array_1.isArray(tag)) { | ||
if (isArray(tag)) { | ||
if (tag.__release) { | ||
@@ -152,3 +154,3 @@ // DEBUG && console.log("call __release", tag); | ||
v = e[2]; | ||
if (is_array_1.isArray(v) && (k = v[1].key) !== undefined) { | ||
if (isArray(v) && (k = v[1].key) !== undefined) { | ||
ek = equiv[k]; | ||
@@ -155,0 +157,0 @@ !ek && (equiv[k] = ek = [, ,]); |
/** | ||
* Creates an actual DOM tree from given hiccup component and `parent` | ||
* element. Calls `init` with created element (user provided context and | ||
* other args) for any components with `init` lifecycle method. Returns | ||
* other args) for any components with `init` life cycle method. Returns | ||
* created root element(s) - usually only a single one, but can be an | ||
@@ -6,0 +6,0 @@ * array of elements, if the provided tree is an iterable. Creates DOM |
24
dom.js
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const is_array_1 = require("@thi.ng/checks/is-array"); | ||
const is_function_1 = require("@thi.ng/checks/is-function"); | ||
const is_iterable_1 = require("@thi.ng/checks/is-iterable"); | ||
const is_string_1 = require("@thi.ng/checks/is-string"); | ||
const isa = require("@thi.ng/checks/is-array"); | ||
const isf = require("@thi.ng/checks/is-function"); | ||
const isi = require("@thi.ng/checks/is-iterable"); | ||
const iss = require("@thi.ng/checks/is-string"); | ||
const api_1 = require("@thi.ng/hiccup/api"); | ||
const css_1 = require("@thi.ng/hiccup/css"); | ||
const map_1 = require("@thi.ng/iterators/map"); | ||
const isArray = isa.isArray; | ||
const isFunction = isf.isFunction; | ||
const isIterable = isi.isIterable; | ||
const isString = iss.isString; | ||
/** | ||
* Creates an actual DOM tree from given hiccup component and `parent` | ||
* element. Calls `init` with created element (user provided context and | ||
* other args) for any components with `init` lifecycle method. Returns | ||
* other args) for any components with `init` life cycle method. Returns | ||
* created root element(s) - usually only a single one, but can be an | ||
@@ -24,5 +28,5 @@ * array of elements, if the provided tree is an iterable. Creates DOM | ||
function createDOM(parent, tag, insert) { | ||
if (is_array_1.isArray(tag)) { | ||
if (isArray(tag)) { | ||
const t = tag[0]; | ||
if (is_function_1.isFunction(t)) { | ||
if (isFunction(t)) { | ||
return createDOM(parent, t.apply(null, tag.slice(1))); | ||
@@ -42,3 +46,3 @@ } | ||
} | ||
if (!is_string_1.isString(tag) && is_iterable_1.isIterable(tag)) { | ||
if (!isString(tag) && isIterable(tag)) { | ||
return [...(map_1.map((x) => createDOM(parent, x), tag))]; | ||
@@ -120,3 +124,3 @@ } | ||
const isListener = id.indexOf("on") === 0; | ||
if (!isListener && is_function_1.isFunction(val)) { | ||
if (!isListener && isFunction(val)) { | ||
val = val(attribs); | ||
@@ -156,3 +160,3 @@ } | ||
case "search": | ||
if (el.value !== undefined && is_string_1.isString(v)) { | ||
if (el.value !== undefined && isString(v)) { | ||
const e = el; | ||
@@ -159,0 +163,0 @@ const off = v.length - (e.value.length - e.selectionStart); |
@@ -49,2 +49,9 @@ /** | ||
* | ||
* In terms of life cycle methods: `render` should ALWAYS return an | ||
* array or another function, else the component's `init` or `release` | ||
* fns will NOT be able to be called. E.g. If the return value of | ||
* `render` evaluates as a string or number, the return value should be | ||
* wrapped as `["span", "foo"]`. If no `init` or `release` are used, | ||
* this requirement is relaxed. | ||
* | ||
* For normal usage only the first 2 args should be specified and the | ||
@@ -51,0 +58,0 @@ * rest kept at their defaults. |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const error_1 = require("@thi.ng/api/error"); | ||
const is_array_1 = require("@thi.ng/checks/is-array"); | ||
const implements_function_1 = require("@thi.ng/checks/implements-function"); | ||
const is_function_1 = require("@thi.ng/checks/is-function"); | ||
const is_iterable_1 = require("@thi.ng/checks/is-iterable"); | ||
const is_plain_object_1 = require("@thi.ng/checks/is-plain-object"); | ||
const is_string_1 = require("@thi.ng/checks/is-string"); | ||
const isa = require("@thi.ng/checks/is-array"); | ||
const impf = require("@thi.ng/checks/implements-function"); | ||
const isf = require("@thi.ng/checks/is-function"); | ||
const isi = require("@thi.ng/checks/is-iterable"); | ||
const iso = require("@thi.ng/checks/is-plain-object"); | ||
const iss = require("@thi.ng/checks/is-string"); | ||
const api_1 = require("@thi.ng/hiccup/api"); | ||
const isArray = isa.isArray; | ||
const isFunction = isf.isFunction; | ||
const implementsFunction = impf.implementsFunction; | ||
const isIterable = isi.isIterable; | ||
const isPlainObject = iso.isPlainObject; | ||
const isString = iss.isString; | ||
/** | ||
@@ -36,7 +42,7 @@ * Expands single hiccup element/component into its canonical form: | ||
function normalizeElement(spec, keys) { | ||
let tag = spec[0], hasAttribs = is_plain_object_1.isPlainObject(spec[1]), match, id, clazz, attribs; | ||
if (!is_string_1.isString(tag) || !(match = api_1.TAG_REGEXP.exec(tag))) { | ||
let tag = spec[0], hasAttribs = isPlainObject(spec[1]), match, id, clazz, attribs; | ||
if (!isString(tag) || !(match = api_1.TAG_REGEXP.exec(tag))) { | ||
error_1.illegalArgs(`${tag} is not a valid tag name`); | ||
} | ||
// return orig if already normalized and satifies key requirement | ||
// return orig if already normalized and satisfies key requirement | ||
if (tag === match[1] && hasAttribs && (!keys || spec[1].key)) { | ||
@@ -91,2 +97,9 @@ return spec; | ||
* | ||
* In terms of life cycle methods: `render` should ALWAYS return an | ||
* array or another function, else the component's `init` or `release` | ||
* fns will NOT be able to be called. E.g. If the return value of | ||
* `render` evaluates as a string or number, the return value should be | ||
* wrapped as `["span", "foo"]`. If no `init` or `release` are used, | ||
* this requirement is relaxed. | ||
* | ||
* For normal usage only the first 2 args should be specified and the | ||
@@ -107,3 +120,3 @@ * rest kept at their defaults. | ||
} | ||
if (is_array_1.isArray(tree)) { | ||
if (isArray(tree)) { | ||
if (tree.length === 0) { | ||
@@ -116,15 +129,11 @@ return; | ||
// pass ctx as first arg and remaining array elements as rest args | ||
if (is_function_1.isFunction(tag)) { | ||
return normalizeTree(tag.apply(null, [ctx, ...tree.slice(1)]), ctx, path.slice(), keys, span); | ||
if (isFunction(tag)) { | ||
return normalizeTree(tag.apply(null, [ctx, ...tree.slice(1)]), ctx, path, keys, span); | ||
} | ||
// component object w/ life cycle methods | ||
// (render() is the only required hook) | ||
if (implements_function_1.implementsFunction(tag, "render")) { | ||
if (implementsFunction(tag, "render")) { | ||
const args = [ctx, ...tree.slice(1)]; | ||
norm = normalizeTree(tag.render.apply(null, args), ctx, path.slice(), keys, span); | ||
if (norm !== undefined) { | ||
nattribs = norm[1]; | ||
if (keys && nattribs.key === undefined) { | ||
nattribs.key = path.join("-"); | ||
} | ||
norm = normalizeTree(tag.render.apply(null, args), ctx, path, keys, span); | ||
if (isArray(norm)) { | ||
norm.__init = tag.init; | ||
@@ -148,4 +157,4 @@ norm.__release = tag.release; | ||
if (el != null) { | ||
const isarray = is_array_1.isArray(el); | ||
if ((isarray && is_array_1.isArray(el[0])) || (!isarray && !is_string_1.isString(el) && is_iterable_1.isIterable(el))) { | ||
const isarray = isArray(el); | ||
if ((isarray && isArray(el[0])) || (!isarray && !isString(el) && isIterable(el))) { | ||
for (let c of el) { | ||
@@ -172,7 +181,7 @@ c = normalizeTree(c, ctx, path.concat(k), keys, span); | ||
} | ||
if (is_function_1.isFunction(tree)) { | ||
if (isFunction(tree)) { | ||
return normalizeTree(tree(ctx), ctx, path, keys, span); | ||
} | ||
if (implements_function_1.implementsFunction(tree, "deref")) { | ||
return normalizeTree(tree.deref(), ctx, path.slice(), keys, span); | ||
if (implementsFunction(tree, "deref")) { | ||
return normalizeTree(tree.deref(), ctx, path, keys, span); | ||
} | ||
@@ -179,0 +188,0 @@ return span ? |
{ | ||
"name": "@thi.ng/hdom", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Lightweight vanilla ES6 UI component & virtual DOM system", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
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
68615
17
793