@endorphinjs/template-runtime
Advanced tools
Comparing version 0.1.21 to 0.1.22
@@ -764,2 +764,15 @@ 'use strict'; | ||
/** | ||
* @param {*} scope | ||
* @param {number} index | ||
* @param {*} key | ||
* @param {*} value | ||
*/ | ||
function prepareScope(scope, index, key, value) { | ||
scope.index = index; | ||
scope.key = key; | ||
scope.value = value; | ||
return scope; | ||
} | ||
/** | ||
* Removes remaining iterator items from current context | ||
@@ -787,3 +800,3 @@ * @param {IteratorBlock} block | ||
const { ptr } = injector; | ||
const localScope = { index, key, value }; | ||
const prevScope = getScope(host); | ||
@@ -796,10 +809,13 @@ /** @type {IteratorItemBlock} */ | ||
if (rendered.update) { | ||
setScope(host, assign(rendered.scope, localScope)); | ||
if (run(rendered, rendered.update, rendered.scope)) { | ||
const scope = prepareScope(rendered.scope, index, key, value); | ||
setScope(host, scope); | ||
if (run(rendered, rendered.update, scope)) { | ||
this.updated = 1; | ||
} | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
} | ||
} else { | ||
// Create & render new block | ||
const scope = prepareScope(obj(prevScope), index, key, value); | ||
/** @type {IteratorItemBlock} */ | ||
@@ -810,3 +826,3 @@ rendered = injectBlock(injector, { | ||
injector, | ||
scope: enterScope(host, localScope), | ||
scope, | ||
dispose: null, | ||
@@ -819,4 +835,5 @@ update: undefined, | ||
rendered.update = run(rendered, this.body, rendered.scope); | ||
exitScope(host); | ||
setScope(host, scope); | ||
rendered.update = run(rendered, this.body, scope); | ||
setScope(host, prevScope); | ||
this.updated = 1; | ||
@@ -839,2 +856,3 @@ } | ||
function mountKeyIterator(host, injector, get, keyExpr, body) { | ||
const parentScope = getScope(host); | ||
/** @type {KeyIteratorBlock} */ | ||
@@ -845,3 +863,3 @@ const block = injectBlock(injector, { | ||
injector, | ||
scope: getScope(host), | ||
scope: obj(parentScope), | ||
dispose: null, | ||
@@ -855,3 +873,3 @@ get, | ||
needReorder: false, | ||
localScope: createScope(host), | ||
parentScope, | ||
order: [], | ||
@@ -895,3 +913,3 @@ used: null, | ||
const collection = block.get(host, block.scope); | ||
const collection = block.get(host, block.parentScope); | ||
if (collection && typeof collection.forEach === 'function') { | ||
@@ -913,6 +931,2 @@ collection.forEach(iterator$1, block); | ||
if (block.index) { | ||
exitScope(host); | ||
} | ||
block.order.length = 0; | ||
@@ -939,5 +953,7 @@ block.rendered = block.used; | ||
const id = getId(this, index, key, value); | ||
// TODO make `rendered` a linked list for faster insert and remove | ||
let entry = rendered && id in rendered ? rendered[id].shift() : null; | ||
const scope = prepareScope(entry ? entry.scope : obj(this.localScope), index, key, value); | ||
const prevScope = getScope(host); | ||
const scope = prepareScope(entry ? entry.scope : obj(this.scope), index, key, value); | ||
setScope(host, scope); | ||
@@ -960,2 +976,4 @@ | ||
setScope(host, prevScope); | ||
markUsed(this, id, entry); | ||
@@ -989,15 +1007,2 @@ injector.ptr = entry.end; | ||
/** | ||
* @param {*} scope | ||
* @param {number} index | ||
* @param {*} key | ||
* @param {*} value | ||
*/ | ||
function prepareScope(scope, index, key, value) { | ||
scope.index = index; | ||
scope.key = key; | ||
scope.value = value; | ||
return scope; | ||
} | ||
/** | ||
* @param {KeyIteratorBlock} iterator | ||
@@ -1027,3 +1032,3 @@ * @param {string} id | ||
function getId(iterator, index, key, value) { | ||
return iterator.keyExpr(value, prepareScope(iterator.localScope, index, key, value)); | ||
return iterator.keyExpr(value, prepareScope(iterator.scope, index, key, value)); | ||
} | ||
@@ -1033,2 +1038,3 @@ | ||
* @param {KeyIteratorBlock} iterator | ||
* @param {Object} scope | ||
* @returns {IteratorItemBlock} | ||
@@ -2014,2 +2020,3 @@ */ | ||
const { host, injector } = ctx; | ||
const prevScope = getScope(host); | ||
let updated = 0; | ||
@@ -2026,3 +2033,3 @@ | ||
ctx.partial = partial; | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
updated = 1; | ||
@@ -2035,3 +2042,3 @@ } else if (ctx.update) { | ||
} | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
} | ||
@@ -2336,4 +2343,3 @@ | ||
exports.unmountIterator = unmountIterator; | ||
exports.iteratorHost = iteratorHost; | ||
exports.trimIteratorItems = trimIteratorItems; | ||
exports.prepareScope = prepareScope; | ||
exports.mountKeyIterator = mountKeyIterator; | ||
@@ -2340,0 +2346,0 @@ exports.updateKeyIterator = updateKeyIterator; |
@@ -760,2 +760,15 @@ /** | ||
/** | ||
* @param {*} scope | ||
* @param {number} index | ||
* @param {*} key | ||
* @param {*} value | ||
*/ | ||
function prepareScope(scope, index, key, value) { | ||
scope.index = index; | ||
scope.key = key; | ||
scope.value = value; | ||
return scope; | ||
} | ||
/** | ||
* Removes remaining iterator items from current context | ||
@@ -783,3 +796,3 @@ * @param {IteratorBlock} block | ||
const { ptr } = injector; | ||
const localScope = { index, key, value }; | ||
const prevScope = getScope(host); | ||
@@ -792,10 +805,13 @@ /** @type {IteratorItemBlock} */ | ||
if (rendered.update) { | ||
setScope(host, assign(rendered.scope, localScope)); | ||
if (run(rendered, rendered.update, rendered.scope)) { | ||
const scope = prepareScope(rendered.scope, index, key, value); | ||
setScope(host, scope); | ||
if (run(rendered, rendered.update, scope)) { | ||
this.updated = 1; | ||
} | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
} | ||
} else { | ||
// Create & render new block | ||
const scope = prepareScope(obj(prevScope), index, key, value); | ||
/** @type {IteratorItemBlock} */ | ||
@@ -806,3 +822,3 @@ rendered = injectBlock(injector, { | ||
injector, | ||
scope: enterScope(host, localScope), | ||
scope, | ||
dispose: null, | ||
@@ -815,4 +831,5 @@ update: undefined, | ||
rendered.update = run(rendered, this.body, rendered.scope); | ||
exitScope(host); | ||
setScope(host, scope); | ||
rendered.update = run(rendered, this.body, scope); | ||
setScope(host, prevScope); | ||
this.updated = 1; | ||
@@ -835,2 +852,3 @@ } | ||
function mountKeyIterator(host, injector, get, keyExpr, body) { | ||
const parentScope = getScope(host); | ||
/** @type {KeyIteratorBlock} */ | ||
@@ -841,3 +859,3 @@ const block = injectBlock(injector, { | ||
injector, | ||
scope: getScope(host), | ||
scope: obj(parentScope), | ||
dispose: null, | ||
@@ -851,3 +869,3 @@ get, | ||
needReorder: false, | ||
localScope: createScope(host), | ||
parentScope, | ||
order: [], | ||
@@ -891,3 +909,3 @@ used: null, | ||
const collection = block.get(host, block.scope); | ||
const collection = block.get(host, block.parentScope); | ||
if (collection && typeof collection.forEach === 'function') { | ||
@@ -909,6 +927,2 @@ collection.forEach(iterator$1, block); | ||
if (block.index) { | ||
exitScope(host); | ||
} | ||
block.order.length = 0; | ||
@@ -935,5 +949,7 @@ block.rendered = block.used; | ||
const id = getId(this, index, key, value); | ||
// TODO make `rendered` a linked list for faster insert and remove | ||
let entry = rendered && id in rendered ? rendered[id].shift() : null; | ||
const scope = prepareScope(entry ? entry.scope : obj(this.localScope), index, key, value); | ||
const prevScope = getScope(host); | ||
const scope = prepareScope(entry ? entry.scope : obj(this.scope), index, key, value); | ||
setScope(host, scope); | ||
@@ -956,2 +972,4 @@ | ||
setScope(host, prevScope); | ||
markUsed(this, id, entry); | ||
@@ -985,15 +1003,2 @@ injector.ptr = entry.end; | ||
/** | ||
* @param {*} scope | ||
* @param {number} index | ||
* @param {*} key | ||
* @param {*} value | ||
*/ | ||
function prepareScope(scope, index, key, value) { | ||
scope.index = index; | ||
scope.key = key; | ||
scope.value = value; | ||
return scope; | ||
} | ||
/** | ||
* @param {KeyIteratorBlock} iterator | ||
@@ -1023,3 +1028,3 @@ * @param {string} id | ||
function getId(iterator, index, key, value) { | ||
return iterator.keyExpr(value, prepareScope(iterator.localScope, index, key, value)); | ||
return iterator.keyExpr(value, prepareScope(iterator.scope, index, key, value)); | ||
} | ||
@@ -1029,2 +1034,3 @@ | ||
* @param {KeyIteratorBlock} iterator | ||
* @param {Object} scope | ||
* @returns {IteratorItemBlock} | ||
@@ -2010,2 +2016,3 @@ */ | ||
const { host, injector } = ctx; | ||
const prevScope = getScope(host); | ||
let updated = 0; | ||
@@ -2022,3 +2029,3 @@ | ||
ctx.partial = partial; | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
updated = 1; | ||
@@ -2031,3 +2038,3 @@ } else if (ctx.update) { | ||
} | ||
exitScope(host); | ||
setScope(host, prevScope); | ||
} | ||
@@ -2322,3 +2329,3 @@ | ||
export { get, filter, call, addDisposeCallback, mountBlock, updateBlock, unmountBlock, mountIterator, updateIterator, unmountIterator, iteratorHost, trimIteratorItems, mountKeyIterator, updateKeyIterator, unmountKeyIterator, createInjector, insert, injectBlock, run, emptyBlockContent, move, disposeBlock, enterScope, exitScope, createScope, setScope, getScope, getProp, getState, getVar, setVar, setAttribute, setAttributeNS, updateAttribute, updateProps, addClass, finalizeAttributes, normalizeClassName, addEvent, addStaticEvent, finalizeEvents, getEventHandler, mountSlot, unmountSlot, updateSlots, markSlotUpdate, setRef, setStaticRef, finalizeRefs, createComponent, mountComponent, updateComponent, unmountComponent, subscribeStore, scheduleRender, renderComponent, mountInnerHTML, updateInnerHTML, unmountInnerHTML, elem, elemNS, elemWithText, elemNSWithText, text, updateText, domInsert, domRemove, mountPartial, updatePartial, unmountPartial, Store, animateIn, animateOut }; | ||
export { get, filter, call, addDisposeCallback, mountBlock, updateBlock, unmountBlock, mountIterator, updateIterator, unmountIterator, prepareScope, mountKeyIterator, updateKeyIterator, unmountKeyIterator, createInjector, insert, injectBlock, run, emptyBlockContent, move, disposeBlock, enterScope, exitScope, createScope, setScope, getScope, getProp, getState, getVar, setVar, setAttribute, setAttributeNS, updateAttribute, updateProps, addClass, finalizeAttributes, normalizeClassName, addEvent, addStaticEvent, finalizeEvents, getEventHandler, mountSlot, unmountSlot, updateSlots, markSlotUpdate, setRef, setStaticRef, finalizeRefs, createComponent, mountComponent, updateComponent, unmountComponent, subscribeStore, scheduleRender, renderComponent, mountInnerHTML, updateInnerHTML, unmountInnerHTML, elem, elemNS, elemWithText, elemNSWithText, text, updateText, domInsert, domRemove, mountPartial, updatePartial, unmountPartial, Store, animateIn, animateOut }; | ||
//# sourceMappingURL=runtime.es.js.map |
{ | ||
"name": "@endorphinjs/template-runtime", | ||
"version": "0.1.21", | ||
"version": "0.1.22", | ||
"description": "EndorphinJS template runtime, embedded with template bundles", | ||
@@ -5,0 +5,0 @@ "main": "./dist/runtime.cjs.js", |
@@ -412,7 +412,3 @@ import { Store } from './lib/store'; | ||
needReorder: boolean; | ||
localScope: { | ||
index: number, | ||
key: any, | ||
value: any | ||
} | ||
parentScope: object; | ||
} | ||
@@ -419,0 +415,0 @@ |
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
342452
4488