Skip to content

Commit

Permalink
closes #1851
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Sep 5, 2016
1 parent 7817cd7 commit 813dcd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/browser/tag/tag.js
Expand Up @@ -213,6 +213,8 @@ export default function Tag(impl, conf, innerHTML) {
updateOpts.call(this)
if (impl.fn) impl.fn.call(this, opts)

this.trigger('before-mount')

// update the root adding custom attributes coming from the compiler
implAttrs = []
walkAttrs(impl.attrs, (k, v) => { implAttrs.push({name: k, value: v}) })
Expand Down
19 changes: 19 additions & 0 deletions test/specs/browser/core.spec.js
Expand Up @@ -562,6 +562,25 @@ describe('Riot core', function() {
expect(incrementEvents).to.have.been.calledTwice
})

it('the before mount event gets triggered before the component markup creation', function() {
injectHTML('<riot-tmp></riot-tmp>')

riot.tag('riot-tmp', `
<p>{ flag }<p>
`, function() {
this.flag = true
this.on('before-mount', () => {
this.flag = false
})
})

var tag = riot.mount('riot-tmp')[0]

expect($('p', tag.root).innerHTML).to.be.equal('false')

tag.unmount()
})

it('all the events get fired also in the loop tags, the e.item property gets preserved', function() {
injectHTML('<events></events>')
var currentItem,
Expand Down

0 comments on commit 813dcd0

Please sign in to comment.