server: Store mount selector and return this (#625)
* Store mount selector and return `this`
This allows `.mount('body')` to be used on the server like so:
```js
module.exports = app.mount('body')
```
Then, when server rendering you can do:
```js
var app = require('./app')
fillServerTemplate(html, app.selector, app.toString('/'))
```
Where `fillServerTemplate` is a function that replaces the HTML at a
CSS selector with some string.
This way you do not need to check for `typeof window` in your
application entry point to do server rendering, and it allows tools like
bankai to automatically inline server rendered html in the correct place.
* docs
* better words
This commit is contained in:
@@ -153,7 +153,12 @@ 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')
|
||||
if (typeof window !== 'object') {
|
||||
assert.ok(typeof selector === 'string', 'choo.mount: selector should be type String')
|
||||
this.selector = selector
|
||||
return this
|
||||
}
|
||||
|
||||
assert.ok(typeof selector === 'string' || typeof selector === 'object', 'choo.mount: selector should be type String or HTMLElement')
|
||||
|
||||
var self = this
|
||||
|
||||
Reference in New Issue
Block a user