Skip to content

Commit

Permalink
added: riot.settings.autoUpdate option closes #2377
Browse files Browse the repository at this point in the history
  • Loading branch information
GianlucaGuarini committed Jun 7, 2017
1 parent 486e520 commit 1a9259b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/browser/tag/if.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { remAttr } from './../common/util/dom'
import { remAttr, createDOMPlaceholder } from './../common/util/dom'
import { tmpl } from 'riot-tmpl'
import { unmountAll } from './../common/util/tags'
import { CONDITIONAL_DIRECTIVE } from './../common/global-variables'
Expand All @@ -10,7 +10,7 @@ export default {
remAttr(dom, CONDITIONAL_DIRECTIVE)
this.tag = tag
this.expr = expr
this.stub = document.createTextNode('')
this.stub = createDOMPlaceholder()
this.pristine = dom

var p = dom.parentNode
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/tag/setEventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isWritable } from './../common/util/check'
import { contains } from './../common/util/misc'
import { RE_EVENTS_PREFIX, RIOT_EVENTS_KEY } from '../common/global-variables'
import { getImmediateCustomParentTag } from './../common/util/tags'
import settings from '../../settings'

/**
* Trigger DOM events
Expand Down Expand Up @@ -31,6 +32,9 @@ function handleEvent(dom, handler, e) {

handler.call(this, e)

// avoid auto updates
if (!settings.autoUpdate) return

if (!e.preventUpdate) {
var p = getImmediateCustomParentTag(this)
// fixes #2083
Expand Down
4 changes: 3 additions & 1 deletion lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ import { extend }from './browser/common/util/misc'
import { brackets } from 'riot-tmpl'

export default extend(Object.create(brackets.settings), {
skipAnonymousTags: true
skipAnonymousTags: true,
// handle the auto updates on any DOM event
autoUpdate: true
})
25 changes: 24 additions & 1 deletion test/specs/browser/riot/core.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ describe('Riot core', function() {

expect(tag.refs['fancy-name'].innerHTML).to.be.equal('john')

fireEvent($$('p')[0], 'click', tag.root)
fireEvent($$('p')[0], 'click')

expect(tag.refs['fancy-name'].innerHTML).to.be.equal('john')

Expand Down Expand Up @@ -1449,4 +1449,27 @@ describe('Riot core', function() {
tag.unmount()
document.body.removeChild(window.tmpsvg)
})

it('disable the auto updates via settings.autoUpdate = false', function() {
injectHTML('<riot-tmp></riot-tmp>')

riot.tag('riot-tmp', '<p ref="p" onclick="{ updateMessage }">{ message }</p>', function() {
this.message = 'hi'
this.updateMessage = function() {
this.message = 'goodbye'
}
})

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

expect(tag.refs.p.innerHTML).to.be.equal(tag.message)

fireEvent(tag.refs.p, 'click')

expect(tag.refs.p.innerHTML).to.be.not.equal(tag.message)

tag.unmount()
riot.settings.autoUpdate = true
})
})

0 comments on commit 1a9259b

Please sign in to comment.