Skip to content

Commit

Permalink
closes #2436
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Sep 2, 2017
1 parent 5d4199f commit 59222aa
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions lib/browser/tag/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,23 @@ function updateOpts(isLoop, parent, isAnonymous, opts, instAttrs) {
}

/**
* Toggle the isMounted flag
* Manage the mount state of a tag triggering also the observable events
* @this Tag
* @param { Boolean } value - ..of the isMounted flag
*/
function setIsMounted(value) {
function setMountState(value) {
const { isAnonymous } = this.__

defineProperty(this, 'isMounted', value)

if (!isAnonymous) {
if (value) this.trigger('mount')
else {
this.trigger('unmount')
this.off('*')
this.__.wasCreated = false
}
}
}


Expand Down Expand Up @@ -104,7 +115,7 @@ export default function Tag(impl = {}, conf = {}, innerHTML) {
if (impl.name && root._tag) root._tag.unmount(true)

// not yet mounted
setIsMounted.call(this, false)
defineProperty(this, 'isMounted', false)

defineProperty(this, '__', {
isAnonymous,
Expand Down Expand Up @@ -282,13 +293,11 @@ export default function Tag(impl = {}, conf = {}, innerHTML) {
if (!skipAnonymous && this.parent) {
const p = getImmediateCustomParentTag(this.parent)
p.one(!p.isMounted ? 'mount' : 'updated', () => {
setIsMounted.call(this, true)
this.trigger('mount')
setMountState.call(this, true)
})
} else {
// otherwise it's not a child tag we can trigger its mount event
setIsMounted.call(this, true)
if (!skipAnonymous) this.trigger('mount')
setMountState.call(this, true)
}

this.__.wasCreated = true
Expand Down Expand Up @@ -365,15 +374,10 @@ export default function Tag(impl = {}, conf = {}, innerHTML) {
// custom internal unmount function to avoid relying on the observable
if (this.__.onUnmount) this.__.onUnmount()

if (!skipAnonymous) {
// weird fix for a weird edge case #2409
if (!this.isMounted) this.trigger('mount')
this.trigger('unmount')
this.off('*')
}
// weird fix for a weird edge case #2409
if (!this.isMounted) setMountState.call(this, true)

defineProperty(this, 'isMounted', false)
this.__.wasCreated = false
setMountState.call(this, false)

delete this.root._tag

Expand Down

0 comments on commit 59222aa

Please sign in to comment.