Save location (#534)

* add location

* remove zopfli from build

* state.location -> state.href

* add state.href docs
This commit is contained in:
Yoshua Wuyts
2017-07-26 19:31:15 +02:00
committed by GitHub
parent 4684f5ef1a
commit 9c8c5b3c85
3 changed files with 11 additions and 7 deletions
+3
View File
@@ -236,6 +236,9 @@ The current params taken from the route. E.g. `/foo/:bar` becomes available as
An object containing the current queryString. `/foo?bin=baz` becomes `{ bin: An object containing the current queryString. `/foo?bin=baz` becomes `{ bin:
'baz' }`. 'baz' }`.
### `state.href`
An object containing the current href. `/foo?bin=baz` becomes `foo`.
### `state.route` ### `state.route`
The current name of the route used in the router (e.g. `/foo/:bar`). The current name of the route used in the router (e.g. `/foo/:bar`).
+7 -5
View File
@@ -122,16 +122,17 @@ Choo.prototype.start = function () {
} }
} }
var location = this._createLocation() this.state.href = this._createLocation()
this._tree = this.router(location) this._tree = this.router(this.state.href)
this.state.query = nanoquery(window.location.search) this.state.query = nanoquery(window.location.search)
assert.ok(this._tree, 'choo.start: no valid DOM node returned for location ' + location) assert.ok(this._tree, 'choo.start: no valid DOM node returned for location ' + this.state.href)
this.emitter.prependListener(self._events.RENDER, nanoraf(function () { this.emitter.prependListener(self._events.RENDER, nanoraf(function () {
var renderTiming = nanotiming('choo.render') var renderTiming = nanotiming('choo.render')
var newTree = self.router(self._createLocation()) self.state.href = self._createLocation()
assert.ok(newTree, 'choo.render: no valid DOM node returned for location ' + location) var newTree = self.router(self.state.href)
assert.ok(newTree, 'choo.render: no valid DOM node returned for location ' + self.state.href)
assert.equal(self._tree.nodeName, newTree.nodeName, 'choo.render: The target node <' + assert.equal(self._tree.nodeName, newTree.nodeName, 'choo.render: The target node <' +
self._tree.nodeName.toLowerCase() + '> is not the same type as the new node <' + self._tree.nodeName.toLowerCase() + '> is not the same type as the new node <' +
@@ -182,6 +183,7 @@ Choo.prototype.toString = function (location, state) {
assert.equal(typeof location, 'string', 'choo.toString: location should be type string') assert.equal(typeof location, 'string', 'choo.toString: location should be type string')
assert.equal(typeof this.state, 'object', 'choo.toString: state should be type object') assert.equal(typeof this.state, 'object', 'choo.toString: state should be type object')
this.state.href = location.replace(/\?*.$/, '')
this.state.query = nanoquery(location) this.state.query = nanoquery(location)
var html = this.router(location) var html = this.router(location)
assert.ok(html, 'choo.toString: no valid value returned for the route ' + location) assert.ok(html, 'choo.toString: no valid value returned for the route ' + location)
+1 -2
View File
@@ -10,7 +10,7 @@
"example" "example"
], ],
"scripts": { "scripts": {
"build": "mkdir -p dist/ && browserify index -p bundle-collapser/plugin > dist/bundle.js && browserify index -g unassertify -g uglifyify -p bundle-collapser/plugin | uglifyjs --mangle-props -c unsafe,properties,dead_code,comparisons,evaluate,hoist_funs,if_return,join_vars,pure_getters,reduce_vars,collapse_vars --toplevel > dist/bundle.min.js && zopfli -i 100 dist/bundle.min.js && wc -c < dist/bundle.min.js.gz | pretty-bytes", "build": "mkdir -p dist/ && browserify index -p bundle-collapser/plugin > dist/bundle.js && browserify index -g unassertify -g uglifyify -p bundle-collapser/plugin | uglifyjs --mangle-props -c unsafe,properties,dead_code,comparisons,evaluate,hoist_funs,if_return,join_vars,pure_getters,reduce_vars,collapse_vars --toplevel > dist/bundle.min.js && cat dist/bundle.min.js | gzip --best --stdout | wc -c | pretty-bytes",
"deps": "dependency-check --entry ./html.js . && dependency-check . --extra --no-dev --entry ./html.js", "deps": "dependency-check --entry ./html.js . && dependency-check . --extra --no-dev --entry ./html.js",
"inspect": "browserify --full-paths index -g unassertify -g uglifyify | discify --open", "inspect": "browserify --full-paths index -g unassertify -g uglifyify | discify --open",
"prepublish": "npm run build", "prepublish": "npm run build",
@@ -46,7 +46,6 @@
"bundle-collapser": "^1.2.1", "bundle-collapser": "^1.2.1",
"dependency-check": "^2.8.0", "dependency-check": "^2.8.0",
"discify": "^1.6.0", "discify": "^1.6.0",
"node-zopfli": "^2.0.2",
"pretty-bytes-cli": "^2.0.0", "pretty-bytes-cli": "^2.0.0",
"spok": "^0.8.1", "spok": "^0.8.1",
"standard": "^10.0.0", "standard": "^10.0.0",