@endorphinjs/template-runtime
Advanced tools
Comparing version 0.5.7 to 0.6.0
@@ -15,2 +15,8 @@ import { Component } from './component'; | ||
} | ||
interface ValueMap { | ||
[name: string]: any; | ||
} | ||
interface ValueMapNS { | ||
[ns: string]: ValueMap; | ||
} | ||
/** | ||
@@ -23,3 +29,3 @@ * Creates new attribute change set | ||
*/ | ||
export declare function propsSet(elem: Component): AttributeChangeSet; | ||
export declare function propsSet(elem: Component, initial?: {}): {}; | ||
/** | ||
@@ -30,2 +36,7 @@ * Alias for `elem.setAttribute` | ||
/** | ||
* Updates element’s `name` attribute value only if it differs from previous value, | ||
* defined in `prev` | ||
*/ | ||
export declare function updateAttribute(elem: Element, prev: ValueMap, name: string, value: any): number; | ||
/** | ||
* Alias for `elem.className` | ||
@@ -35,2 +46,6 @@ */ | ||
/** | ||
* Shorthand to update class name, specific to Endorphin compiled code | ||
*/ | ||
export declare function updateClass(elem: Element, prev: ValueMap, value: any): number; | ||
/** | ||
* Sets attribute value as expression. Unlike regular primitive attributes, | ||
@@ -51,2 +66,7 @@ * expression values must be represented, e.g. non-primitive values must be | ||
/** | ||
* Updates element’s `name` attribute value only if it differs from previous value, | ||
* defined in `prev` | ||
*/ | ||
export declare function updateAttributeNS(elem: Element, prevNS: ValueMapNS, ns: string, name: string, value: any): number; | ||
/** | ||
* Same as `setAttributeExpression()` but for namespaced attributes | ||
@@ -76,19 +96,28 @@ */ | ||
/** | ||
* Sets pending namespaced attribute value which will be added to attribute later | ||
* Sets pending namespaced attribute value which will be added to element later | ||
*/ | ||
export declare function setPendingAttributeNS(data: AttributeChangeSet, ns: string, name: string, value: any): void; | ||
export declare function setPendingAttributeNS(attrs: ValueMapNS, ns: string, name: string, value: any): void; | ||
/** | ||
* Updates pending `name` value only if given `value` is not null | ||
*/ | ||
export declare function updatePendingAttribute(attrs: ValueMap, name: string, value: any): void; | ||
/** | ||
* Updates pending namespaced `name` value only if given `value` is not null | ||
*/ | ||
export declare function updatePendingAttributeNS(attrs: ValueMap, ns: string, name: string, value: any): void; | ||
/** | ||
* Adds given class name to pending attribute set | ||
*/ | ||
export declare function addPendingClass(data: AttributeChangeSet, className: string): void; | ||
export declare function addPendingClass(data: ValueMap, className: string): void; | ||
/** | ||
* Adds given class name to pending attribute set if condition is truthy | ||
*/ | ||
export declare function addPendingClassIf(data: AttributeChangeSet, className: string, condition: any): void; | ||
export declare function addPendingClassIf(data: ValueMap, className: string, condition: any): void; | ||
/** | ||
* Finalizes pending attributes | ||
*/ | ||
export declare function finalizeAttributes(elem: Element, data: AttributeChangeSet): number; | ||
export declare function finalizeAttributes(elem: Element, cur: ValueMap, prev: ValueMap): number; | ||
/** | ||
* Finalizes pending namespaced attributes | ||
* TODO remove | ||
*/ | ||
@@ -100,1 +129,2 @@ export declare function finalizeAttributesNS(elem: Element, data: AttributeChangeSet): number; | ||
export declare function classNames(str: string): string[]; | ||
export {}; |
@@ -269,2 +269,4 @@ /** | ||
/** Base object to create pending namespaced attribute set */ | ||
const nsProto = obj(); | ||
/** | ||
@@ -279,8 +281,5 @@ * Creates new attribute change set | ||
*/ | ||
function propsSet(elem) { | ||
const props = assign(obj(), elem.componentModel.defaultProps); | ||
// NB in components, pending `c` props are tested against actual `.props`, | ||
// the `p` property is not used. To keep up with the same hidden JS class, | ||
// create `p` property as well and point it to `c` to reduce object allocations | ||
return { c: props, p: props }; | ||
function propsSet(elem, initial) { | ||
const base = obj(elem.componentModel.defaultProps); | ||
return initial ? assign(base, initial) : base; | ||
} | ||
@@ -295,2 +294,20 @@ /** | ||
/** | ||
* Updates element’s `name` attribute value only if it differs from previous value, | ||
* defined in `prev` | ||
*/ | ||
function updateAttribute(elem, prev, name, value) { | ||
if (value !== prev[name]) { | ||
const primitive = representedValue(value); | ||
if (primitive === null) { | ||
elem.removeAttribute(name); | ||
} | ||
else { | ||
setAttribute(elem, name, primitive); | ||
} | ||
prev[name] = value; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
/** | ||
* Alias for `elem.className` | ||
@@ -303,2 +320,8 @@ */ | ||
/** | ||
* Shorthand to update class name, specific to Endorphin compiled code | ||
*/ | ||
function updateClass(elem, prev, value) { | ||
return updateAttribute(elem, prev, 'class', value === '' ? undefined : value); | ||
} | ||
/** | ||
* Sets attribute value as expression. Unlike regular primitive attributes, | ||
@@ -332,2 +355,21 @@ * expression values must be represented, e.g. non-primitive values must be | ||
/** | ||
* Updates element’s `name` attribute value only if it differs from previous value, | ||
* defined in `prev` | ||
*/ | ||
function updateAttributeNS(elem, prevNS, ns, name, value) { | ||
const prev = ns in prevNS ? prevNS[ns] : (prevNS[ns] = obj()); | ||
if (value !== prev[name]) { | ||
const primitive = representedValue(value); | ||
if (primitive === null) { | ||
elem.removeAttributeNS(ns, name); | ||
} | ||
else { | ||
setAttributeNS(elem, ns, name, primitive); | ||
} | ||
prev[name] = value; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
/** | ||
* Same as `setAttributeExpression()` but for namespaced attributes | ||
@@ -379,12 +421,23 @@ */ | ||
/** | ||
* Sets pending namespaced attribute value which will be added to attribute later | ||
* Sets pending namespaced attribute value which will be added to element later | ||
*/ | ||
function setPendingAttributeNS(data, ns, name, value) { | ||
if (!data.n) { | ||
data.n = obj(); | ||
function setPendingAttributeNS(attrs, ns, name, value) { | ||
const map = pendingNS(attrs, ns); | ||
map[name] = value; | ||
} | ||
/** | ||
* Updates pending `name` value only if given `value` is not null | ||
*/ | ||
function updatePendingAttribute(attrs, name, value) { | ||
if (value != null) { | ||
attrs[name] = value; | ||
} | ||
if (!data.n[ns]) { | ||
data.n[ns] = attributeSet(); | ||
} | ||
/** | ||
* Updates pending namespaced `name` value only if given `value` is not null | ||
*/ | ||
function updatePendingAttributeNS(attrs, ns, name, value) { | ||
if (value != null) { | ||
pendingNS(attrs, ns)[name] = value; | ||
} | ||
data.n[ns].c[name] = value; | ||
} | ||
@@ -396,4 +449,4 @@ /** | ||
if (className != null) { | ||
const prev = data.c.class; | ||
data.c.class = prev ? prev + ' ' + className : String(className); | ||
const prev = data.class; | ||
data.class = prev ? prev + ' ' + className : String(className); | ||
} | ||
@@ -410,18 +463,32 @@ } | ||
*/ | ||
function finalizeAttributes(elem, data) { | ||
function finalizeAttributes(elem, cur, prev) { | ||
let updated = 0; | ||
const { c, p } = data; | ||
for (const name in c) { | ||
const curValue = c[name]; | ||
if (curValue !== p[name]) { | ||
updated = 1; | ||
if (name === 'class') { | ||
elem.className = classNames(curValue).join(' '); | ||
for (const key in cur) { | ||
const curValue = cur[key]; | ||
if (isPendingNS(curValue)) { | ||
// It’s a pending attribute set | ||
const prevNS = pendingNS(prev, key); | ||
for (const name in curValue) { | ||
const curNS = curValue[name]; | ||
if (curNS !== prevNS[name]) { | ||
updated = 1; | ||
setAttributeExpressionNS(elem, key, name, curNS); | ||
prevNS[name] = curNS; | ||
} | ||
curValue[name] = null; | ||
} | ||
else { | ||
setAttributeExpression(elem, name, curValue); | ||
} | ||
else { | ||
if (curValue !== prev[key]) { | ||
updated = 1; | ||
if (key === 'class') { | ||
elem.className = classNames(curValue).join(' '); | ||
} | ||
else { | ||
setAttributeExpression(elem, key, curValue); | ||
} | ||
prev[key] = curValue; | ||
} | ||
p[name] = curValue; | ||
cur[key] = null; | ||
} | ||
c[name] = null; | ||
} | ||
@@ -432,2 +499,3 @@ return updated; | ||
* Finalizes pending namespaced attributes | ||
* TODO remove | ||
*/ | ||
@@ -493,2 +561,15 @@ function finalizeAttributesNS(elem, data) { | ||
} | ||
/** | ||
* Check if given object is a pending namespaced attribute set | ||
*/ | ||
function isPendingNS(data) { | ||
return data != null && typeof data === 'object' && Object.getPrototypeOf(data) === nsProto; | ||
} | ||
/** | ||
* Ensures given attribute value map contains namespace map for given `ns` and | ||
* returns it | ||
*/ | ||
function pendingNS(attrs, ns) { | ||
return ns in attrs ? attrs[ns] : (attrs[ns] = Object.create(nsProto)); | ||
} | ||
@@ -2060,3 +2141,3 @@ /** | ||
export default endorphin; | ||
export { Store, addClass, addClassIf, addEvent, addPendingClass, addPendingClassIf, animate, appendChild, assign, attributeSet, call, classNames, composeTween, createAnimation, createComponent, createComponentFromElement, createInjector, createScope, createSlot, cssAnimate, detachPendingEvents, disposeBlock, domInsert, domRemove, elem, elemNS, elemNSWithText, elemWithText, emptyBlockContent, enterScope, exitScope, filter, finalizeAttributes, finalizeAttributesNS, finalizePendingEvents, finalizePendingRefs, find, get, getPartial, getProp, getScope, getSlotContext, getState, getVar, injectBlock, insert, isolateElement, mountBlock, mountComponent, mountInnerHTML, mountIterator, mountKeyIterator, mountPartial, mountSlot, move, notifySlotUpdate, obj, pendingEvents, prepareScope, propsSet, removeEvent, removeRef, renderComponent, safeEventListener, scheduleRender, setAttribute, setAttributeExpression, setAttributeExpressionNS, setAttributeNS, setClass, setPendingAttribute, setPendingAttributeNS, setPendingEvent, setPendingRef, setRef, setScope, setVar, stopAnimation, subscribeStore, text, toggleClassIf, tweenAnimate, unmountBlock, unmountComponent, unmountInnerHTML, unmountIterator, unmountKeyIterator, unmountPartial, unmountSlot, updateAttributeExpression, updateAttributeExpressionNS, updateBlock, updateComponent, updateDefaultSlot, updateIncomingSlot, updateInnerHTML, updateIterator, updateKeyIterator, updatePartial, updateText }; | ||
export { Store, addClass, addClassIf, addEvent, addPendingClass, addPendingClassIf, animate, appendChild, assign, attributeSet, call, classNames, composeTween, createAnimation, createComponent, createComponentFromElement, createInjector, createScope, createSlot, cssAnimate, detachPendingEvents, disposeBlock, domInsert, domRemove, elem, elemNS, elemNSWithText, elemWithText, emptyBlockContent, enterScope, exitScope, filter, finalizeAttributes, finalizeAttributesNS, finalizePendingEvents, finalizePendingRefs, find, get, getPartial, getProp, getScope, getSlotContext, getState, getVar, injectBlock, insert, isolateElement, mountBlock, mountComponent, mountInnerHTML, mountIterator, mountKeyIterator, mountPartial, mountSlot, move, notifySlotUpdate, obj, pendingEvents, prepareScope, propsSet, removeEvent, removeRef, renderComponent, safeEventListener, scheduleRender, setAttribute, setAttributeExpression, setAttributeExpressionNS, setAttributeNS, setClass, setPendingAttribute, setPendingAttributeNS, setPendingEvent, setPendingRef, setRef, setScope, setVar, stopAnimation, subscribeStore, text, toggleClassIf, tweenAnimate, unmountBlock, unmountComponent, unmountInnerHTML, unmountIterator, unmountKeyIterator, unmountPartial, unmountSlot, updateAttribute, updateAttributeExpression, updateAttributeExpressionNS, updateAttributeNS, updateBlock, updateClass, updateComponent, updateDefaultSlot, updateIncomingSlot, updateInnerHTML, updateIterator, updateKeyIterator, updatePartial, updatePendingAttribute, updatePendingAttributeNS, updateText }; | ||
//# sourceMappingURL=runtime.es.js.map |
@@ -27,4 +27,4 @@ import { Changes, ChangeSet } from './types'; | ||
<T, U>(target: T, source: U): T & U; | ||
<T, U, V>(target: T, source1: U, source2: V): T & U & V; | ||
<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W; | ||
<T_1, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V; | ||
<T_2, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W; | ||
(target: object, ...sources: any[]): any; | ||
@@ -31,0 +31,0 @@ }; |
{ | ||
"name": "@endorphinjs/template-runtime", | ||
"version": "0.5.7", | ||
"version": "0.6.0", | ||
"description": "EndorphinJS template runtime, embedded with template bundles", | ||
@@ -26,11 +26,11 @@ "main": "./dist/runtime.cjs.js", | ||
"devDependencies": { | ||
"@endorphinjs/template-compiler": "^0.5.7", | ||
"@types/mocha": "^5.2.6", | ||
"@types/node": "^11.13.10", | ||
"mocha": "^6.1.4", | ||
"rollup": "^1.11.3", | ||
"@endorphinjs/template-compiler": "^0.6.0", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^12.11.1", | ||
"mocha": "^6.2.2", | ||
"rollup": "^1.25.1", | ||
"rollup-plugin-typescript": "^1.0.1", | ||
"ts-node": "^8.3.0", | ||
"tslint": "^5.17.0", | ||
"typescript": "^3.5.2" | ||
"ts-node": "^8.4.1", | ||
"tslint": "^5.20.0", | ||
"typescript": "^3.6.4" | ||
}, | ||
@@ -53,3 +53,3 @@ "directories": { | ||
}, | ||
"gitHead": "3ae6c86ba95ad44b2f7b71bd751db48ad2b0aae6" | ||
"gitHead": "dac024b0d362eb1175b7d535c1eaecc3d9a262f3" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
441650
5255