use ternary, hash is opt-in
This commit is contained in:
@@ -192,12 +192,9 @@ function choo () {
|
|||||||
// initial application state model
|
// initial application state model
|
||||||
// obj -> obj
|
// obj -> obj
|
||||||
function appInit (opts) {
|
function appInit (opts) {
|
||||||
var initialLocation
|
const initialLocation = (opts.hash === true)
|
||||||
if (opts.history !== false) {
|
? hashMatch(document.location.hash)
|
||||||
initialLocation = document.location.href
|
: document.location.href
|
||||||
} else {
|
|
||||||
initialLocation = hashMatch(document.location.hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
const model = {
|
const model = {
|
||||||
namespace: 'app',
|
namespace: 'app',
|
||||||
@@ -213,18 +210,18 @@ function appInit (opts) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable catching <href a=""></href> links
|
// if hash routing explicitly enabled, subscribe to it
|
||||||
// enable HTML5 history API
|
if (opts.hash === true) {
|
||||||
if (opts.href !== false) pushLocationSub(href)
|
|
||||||
if (opts.history !== false) {
|
|
||||||
pushLocationSub(history)
|
|
||||||
// otherwise enable hash history
|
|
||||||
} else {
|
|
||||||
pushLocationSub(function (navigate) {
|
pushLocationSub(function (navigate) {
|
||||||
hash(function (fragment) {
|
hash(function (fragment) {
|
||||||
navigate(hashMatch(fragment))
|
navigate(hashMatch(fragment))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
// otherwise, subscribe to HTML5 history API
|
||||||
|
} else {
|
||||||
|
if (opts.history !== false) pushLocationSub(history)
|
||||||
|
// enable catching <a href=""></a> links
|
||||||
|
if (opts.href !== false) pushLocationSub(href)
|
||||||
}
|
}
|
||||||
|
|
||||||
return model
|
return model
|
||||||
|
|||||||
Reference in New Issue
Block a user