Skip to content

Commit ec4e867

Browse files
committed
Support for shitty babel stuff
1 parent 0a4e73b commit ec4e867

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Slim.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ class Slim extends HTMLElement {
342342
}
343343

344344
createdCallback() {
345+
// __createdCallbackRunOnce is required for babel louzy transpiling
345346
if (this.isVirtual) return;
347+
if (this.__createdCallbackRunOnce) return;
348+
this.__createdCallbackRunOnce = true;
346349
this.initialize();
347350
this.onBeforeCreated();
348351
this._captureBindings();
@@ -435,6 +438,7 @@ class Slim extends HTMLElement {
435438

436439

437440
_executeBindings(prop) {
441+
if (!this._bindings) return;
438442
// reset bound texts
439443
this._boundChildren.forEach( child => {
440444
// this._boundChildren.forEach( child => {
@@ -466,14 +470,16 @@ class Slim extends HTMLElement {
466470
let $tpl = this.alternateTemplate || this.template;
467471
if (!$tpl) {
468472
while (this.children.length) {
469-
this._virtualDOM.appendChild( this.children[0] )
473+
// TODO: find why this line is needed for babel!!!
474+
self._virtualDOM = this._virtualDOM || document.createElement('slim-root')
475+
self._virtualDOM.appendChild( this.children[0] )
470476
}
471477
} else if (typeof($tpl) === 'string') {
472478
this._virtualDOM.innerHTML = $tpl;
473479
let virtualContent = this._virtualDOM.querySelector('slim-content');
474480
if (virtualContent) {
475-
while (this.children.length) {
476-
this.children[0]._boundParent = this.children[0]._boundParent || this;
481+
while (self.children.length) {
482+
self.children[0]._boundParent = this.children[0]._boundParent || this;
477483
virtualContent.appendChild( this.children[0] )
478484
}
479485
}
@@ -483,7 +489,9 @@ class Slim extends HTMLElement {
483489
for (let child of allChildren) {
484490
child._sourceOuterHTML = child.outerHTML;
485491
child._boundParent = child._boundParent || this;
486-
this._boundChildren.push(child);
492+
self._boundChildren = this._boundChildren || [];
493+
self._boundChildren.push(child);
494+
self._boundChildren.push(child);
487495
if (child.getAttribute('slim-id')) {
488496
child._boundParent[ Slim.__dashToCamel(child.getAttribute('slim-id')) ] = child
489497
}

0 commit comments

Comments
 (0)