@erickmerchant/framework
Advanced tools
Comparing version 41.8.0 to 42.0.0
@@ -5,28 +5,14 @@ const svgNamespace = 'http://www.w3.org/2000/svg' | ||
const resolve = (obj) => { | ||
if (typeof obj === 'function') { | ||
let afterUpdate | ||
const readMeta = (target) => { | ||
let result = weakMap.get(target) | ||
obj = obj((cb) => { | ||
afterUpdate = async (el) => cb(el) | ||
}) | ||
if (!result) { | ||
result = {} | ||
if (obj) obj.afterUpdate = afterUpdate | ||
weakMap.set(target, result) | ||
} | ||
return obj | ||
return result | ||
} | ||
const readMeta = (target, meta = {}) => { | ||
if (!meta._read) { | ||
const read = weakMap.get(target) | ||
Object.assign(meta, read ?? {}) | ||
meta._read = true | ||
} | ||
return meta | ||
} | ||
const getNextSibling = (current) => current?.nextSibling | ||
@@ -48,3 +34,3 @@ | ||
const morphAttribute = (target, key, value, meta, listeners) => { | ||
const morphAttribute = (target, key, value) => { | ||
const remove = value == null || value === false | ||
@@ -55,10 +41,14 @@ | ||
readMeta(target, meta) | ||
const meta = readMeta(target) | ||
meta[type] = remove ? null : value | ||
if (!remove && !listeners.includes(type)) { | ||
listeners.push(type) | ||
if (!remove) { | ||
const listeners = readMeta(target.ownerDocument) | ||
addListener(target.ownerDocument, type) | ||
if (!listeners[type]) { | ||
listeners[type] = true | ||
addListener(target.ownerDocument, type) | ||
} | ||
} | ||
@@ -84,10 +74,3 @@ } else { | ||
const morphChild = ( | ||
target, | ||
childNode, | ||
next, | ||
variables, | ||
isSameView, | ||
listeners | ||
) => { | ||
const morphChild = (target, childNode, next, variables, isSameView) => { | ||
const document = target.ownerDocument | ||
@@ -112,23 +95,22 @@ | ||
} else { | ||
const tag = next.tag | ||
if (!append) { | ||
const nodeName = childNode.nodeName | ||
if ( | ||
!append && | ||
(childNode.nodeType !== 1 || childNode.nodeName.toLowerCase() !== tag) | ||
) { | ||
replace = true | ||
if (childNode.nodeType !== 1 || nodeName.toLowerCase() !== next.tag) { | ||
replace = true | ||
} | ||
} | ||
if (append || replace) { | ||
const isSvg = tag === 'svg' || target.namespaceURI === svgNamespace | ||
const isSvg = next.tag === 'svg' || target.namespaceURI === svgNamespace | ||
currentChild = isSvg | ||
? document.createElementNS(svgNamespace, tag) | ||
: document.createElement(tag) | ||
? document.createElementNS(svgNamespace, next.tag) | ||
: document.createElement(next.tag) | ||
} | ||
if (next.view != null) { | ||
morphRoot(currentChild, next, listeners) | ||
morphRoot(currentChild, next) | ||
} else if (!isSameView || next.dynamic) { | ||
morph(currentChild, next, variables, isSameView, {}, listeners) | ||
morph(currentChild, next, variables, isSameView) | ||
} | ||
@@ -143,10 +125,6 @@ } | ||
if (currentChild != null && next.afterUpdate) { | ||
next.afterUpdate(currentChild) | ||
} | ||
return getNextSibling(currentChild) | ||
} | ||
const morph = (target, next, variables, isSameView, meta, listeners) => { | ||
const morph = (target, next, variables, isSameView) => { | ||
const attributesLength = next.attributes.length | ||
@@ -156,27 +134,25 @@ | ||
if (attributesLength) { | ||
for (let i = 0, length = attributesLength; i < length; i++) { | ||
const attribute = next.attributes[i] | ||
for (let i = 0, length = attributesLength; i < length; i++) { | ||
const attribute = next.attributes[i] | ||
if (!isSameView || attribute.variable) { | ||
let value = attribute.value | ||
if (!isSameView || attribute.variable) { | ||
let value = attribute.value | ||
if (attribute.variable) { | ||
value = variables[value] | ||
} | ||
if (attribute.variable) { | ||
value = variables[value] | ||
} | ||
if (attribute.key) { | ||
morphAttribute(target, attribute.key, value, meta, listeners) | ||
if (attribute.key) { | ||
morphAttribute(target, attribute.key, value) | ||
attrNames.push(attribute.key) | ||
} else { | ||
const keys = Object.keys(value) | ||
attrNames.push(attribute.key) | ||
} else { | ||
const keys = Object.keys(value) | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
const key = keys[i] | ||
for (let i = 0, len = keys.length; i < len; i++) { | ||
const key = keys[i] | ||
morphAttribute(target, key, value[key], meta, listeners) | ||
morphAttribute(target, key, value[key]) | ||
attrNames.push(key) | ||
} | ||
attrNames.push(key) | ||
} | ||
@@ -198,54 +174,32 @@ } | ||
if (childrenLength) { | ||
let deopt = !isSameView | ||
let deopt = !isSameView | ||
for (let childIndex = 0; childIndex < childrenLength; childIndex++) { | ||
let child = next.children[childIndex] | ||
for (let childIndex = 0; childIndex < childrenLength; childIndex++) { | ||
let child = next.children[childIndex] | ||
if (!deopt && !child.dynamic && !child.variable) { | ||
childNode = getNextSibling(childNode) | ||
} else { | ||
deopt = true | ||
if (!deopt && !child.dynamic && !child.variable) { | ||
childNode = getNextSibling(childNode) | ||
} else { | ||
deopt = true | ||
if (child.variable) { | ||
const variableValue = child.value | ||
if (child.variable) { | ||
const variableValue = child.value | ||
child = variables[variableValue] | ||
child = variables[variableValue] | ||
if (child?.[Symbol.iterator] == null || typeof child === 'string') { | ||
child = [child] | ||
if (typeof child === 'string') { | ||
child = [{type: 'text', value: child}] | ||
} else if (child?.[Symbol.iterator] == null) { | ||
child = [child] | ||
} | ||
for (let grand of child) { | ||
if (grand == null || grand.type == null) { | ||
grand = {type: 'text', value: grand == null ? '' : grand} | ||
} | ||
for (let grand of child) { | ||
grand = resolve(grand) | ||
if (grand == null) grand = '' | ||
if (grand.type == null) { | ||
grand = {type: 'text', value: grand} | ||
} | ||
if (isSameView && grand.view != null && !grand.dynamic) { | ||
childNode = getNextSibling(childNode) | ||
} else { | ||
childNode = morphChild( | ||
target, | ||
childNode, | ||
grand, | ||
variables, | ||
isSameView, | ||
listeners | ||
) | ||
} | ||
} | ||
} else { | ||
childNode = morphChild( | ||
target, | ||
childNode, | ||
child, | ||
variables, | ||
isSameView, | ||
listeners | ||
) | ||
childNode = morphChild(target, childNode, grand, variables, false) | ||
} | ||
} else { | ||
childNode = morphChild(target, childNode, child, variables, isSameView) | ||
} | ||
@@ -266,13 +220,5 @@ } | ||
} | ||
if (meta._read) { | ||
weakMap.set(target, meta) | ||
} | ||
} | ||
const morphRoot = (target, next, listeners) => { | ||
if (next.view === 0) { | ||
return | ||
} | ||
const morphRoot = (target, next) => { | ||
const meta = readMeta(target) | ||
@@ -287,3 +233,3 @@ | ||
if (!isSameView || next.dynamic) { | ||
morph(target, next, next.variables, isSameView, meta, listeners) | ||
morph(target, next, next.variables, isSameView) | ||
} | ||
@@ -293,13 +239,7 @@ } | ||
export const createDomView = (target, view) => { | ||
const listeners = [] | ||
return (state) => { | ||
const current = resolve(view(state)) | ||
const current = view(state) | ||
morphRoot(target, current, listeners) | ||
if (current.afterUpdate) { | ||
current.afterUpdate(target) | ||
} | ||
morphRoot(target, current) | ||
} | ||
} |
@@ -20,2 +20,4 @@ const weakMap = new WeakMap() | ||
*get(acc, strs, vlength) { | ||
let afterVar = false | ||
for (let index = 0, length = strs.length; index < length; index++) { | ||
@@ -47,2 +49,4 @@ const str = strs[index] | ||
afterVar = false | ||
yield { | ||
@@ -137,3 +141,3 @@ type: !end ? 'tag' : 'endtag', | ||
if (value) { | ||
if (value.trim() || (afterVar && current() !== '<')) { | ||
yield { | ||
@@ -150,2 +154,4 @@ type: 'text', | ||
if (index < vlength) { | ||
afterVar = true | ||
yield { | ||
@@ -152,0 +158,0 @@ type: 'variable', |
{ | ||
"name": "@erickmerchant/framework", | ||
"version": "41.8.0", | ||
"version": "42.0.0", | ||
"description": "A front-end framework.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/erickmerchant/framework#readme", |
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
16875
541