@jeefo/component
Advanced tools
Comparing version 0.0.2 to 0.0.4
/* -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. | ||
* File Name : for_each.js | ||
* Created at : 2017-07-25 | ||
* Updated at : 2019-10-26 | ||
* Updated at : 2019-11-02 | ||
* Author : jeefo | ||
@@ -24,3 +24,5 @@ * Purpose : | ||
const comp_prop = Symbol("component"); | ||
const values_prop = Symbol("values"); | ||
const definition = { | ||
@@ -34,2 +36,5 @@ binders : [], | ||
const DOCUMENT_FRAGMENT_NODE = 11; | ||
const is_fragment = element => element.nodeType === DOCUMENT_FRAGMENT_NODE; | ||
async function create_new_child (value, index, component) { | ||
@@ -57,3 +62,3 @@ const { variable_name, index_name } = component; | ||
const values = instance[values_prop]; | ||
const component = instance["(component)"]; | ||
const component = instance[comp_prop]; | ||
const { children } = component; | ||
@@ -114,3 +119,3 @@ | ||
async on_init ($element, component) { | ||
this["(component)"] = component; | ||
this[comp_prop] = component; | ||
@@ -140,6 +145,4 @@ try { | ||
const comment = ` For each: ${ component.expression } `; | ||
const comment_node = jqlite(document.createComment(comment)); | ||
this["(comment)"] = comment_node; | ||
$element.replace(comment_node); | ||
const comment = ` For each: ${ component.expression } `; | ||
$element.replace(document.createComment(comment)); | ||
@@ -153,4 +156,5 @@ await this.on_digest(); | ||
async on_digest () { | ||
const component = this["(component)"]; | ||
const component = this[comp_prop]; | ||
const { | ||
$element : $comment, | ||
children, | ||
@@ -165,6 +169,11 @@ index_name, | ||
if ($comment.DOM_element.parentNode === null) { | ||
const frag = document.createDocumentFragment(); | ||
frag.appendChild($comment.DOM_element); | ||
} | ||
children.forEach((child, index) => { | ||
if (! child.is_attached || child.index !== index) { | ||
if (index === 0) { | ||
this["(comment)"].after(child.$element); | ||
$comment.after(child.$element); | ||
} else { | ||
@@ -171,0 +180,0 @@ const prev = component.children[index - 1]; |
{ | ||
"name": "@jeefo/component", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/je3f0o/jeefo_component", | ||
@@ -5,0 +5,0 @@ "copyright": "2019", |
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
97500
2943