add initial state support (#574)

* add initial state support

* clean up initial state from window

* fix initial state if none
This commit is contained in:
Yoshua Wuyts
2017-10-20 16:30:58 +02:00
committed by GitHub
parent 2f970403d5
commit 5561566dd5
2 changed files with 35 additions and 3 deletions
+10 -1
View File
@@ -45,7 +45,16 @@ function Choo (opts) {
// properties that are part of the API
this.router = nanorouter({ curry: true })
this.emitter = nanobus('choo.emit')
this.state = { events: this._events }
var events = { events: this._events }
if (this.hasWindow) {
this.state = window.initialState
? xtend(window.initialState, events)
: events
delete window.initialState
} else {
this.state = events
}
// listen for title changes; available even when calling .toString()
if (this._hasWindow) this.state.title = document.title