add support for HTMLElement on choo.mount (#597)
* add support for HTMLElement on choo.mount - removed explicit "string" test and for selector variable, replaced by "is available and filled" test - add "if" to separate by incoming "string" or "HTMLElement" * remove semicolons and white spaces * add "is in Browser" check for HTMLElement * add window to HTMLElement * optimizing "mount" commit * remove window.HTMLElement check * change .mount documentation - add info that selector can be also a DOM element - remove "nanomount" infos * add missing line
This commit is contained in:
@@ -169,15 +169,19 @@ Choo.prototype.start = function () {
|
||||
|
||||
Choo.prototype.mount = function mount (selector) {
|
||||
assert.equal(typeof window, 'object', 'choo.mount: window was not found. .mount() must be called in a browser, use .toString() if running in Node')
|
||||
assert.equal(typeof selector, 'string', 'choo.mount: selector should be type string')
|
||||
assert.ok(typeof selector === 'string' || typeof selector === 'object', 'choo.mount: selector should be type String or HTMLElement')
|
||||
|
||||
var self = this
|
||||
|
||||
documentReady(function () {
|
||||
var renderTiming = nanotiming('choo.render')
|
||||
var newTree = self.start()
|
||||
if (typeof selector === 'string') {
|
||||
self._tree = document.querySelector(selector)
|
||||
} else {
|
||||
self._tree = selector
|
||||
}
|
||||
|
||||
self._tree = document.querySelector(selector)
|
||||
assert.ok(self._tree, 'choo.mount: could not query selector: ' + selector)
|
||||
assert.equal(self._tree.nodeName, newTree.nodeName, 'choo.mount: The target node <' +
|
||||
self._tree.nodeName.toLowerCase() + '> is not the same type as the new node <' +
|
||||
|
||||
Reference in New Issue
Block a user