Skip to content

Commit

Permalink
ensure options.el is element when initializing props
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 25, 2015
1 parent ab8b0e9 commit 25eee91
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/api/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ exports.$mount = function (el) {
_.warn('$mount() should be called only once.')
return
}
el = _.query(el)
if (!el) {
el = document.createElement('div')
} else if (typeof el === 'string') {
var selector = el
el = document.querySelector(el)
if (!el) {
_.warn('Cannot find element: ' + selector)
return
}
}
this._compile(el)
this._isCompiled = true
Expand Down Expand Up @@ -70,4 +64,4 @@ exports.$destroy = function (remove, deferCleanup) {

exports.$compile = function (el, host) {
return compiler.compile(el, this.$options, true, host)(this, el)
}
}
12 changes: 7 additions & 5 deletions src/instance/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ exports._initProps = function () {
var options = this.$options
var el = options.el
var props = options.props
this._propsUnlinkFn = el && props
? compiler.compileAndLinkProps(
this, el, props
)
: null
if (props && !el) {
_.warn(
'Props will not be compiled if no `el` option is ' +
'provided at instantiation.'
)
}
// make sure to convert string selectors into element now
el = options.el = _.query(el)
this._propsUnlinkFn = el && props
? compiler.compileAndLinkProps(
this, el, props
)
: null
}

/**
Expand Down
19 changes: 19 additions & 0 deletions src/util/dom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
var _ = require('./index')
var config = require('../config')

/**
* Query an element selector if it's not an element already.
*
* @param {String|Element} el
* @return {Element}
*/

exports.query = function (el) {
if (typeof el === 'string') {
var selector = el
el = document.querySelector(el)
if (!el) {
_.warn('Cannot find element: ' + selector)
}
}
return el
}

/**
* Check if a node is in the document.
* Note: document.documentElement.contains should work here
Expand Down

0 comments on commit 25eee91

Please sign in to comment.