-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
31 lines (22 loc) · 828 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const assert = require('assert')
const Choo = require('choo')
function Detached (opts) {
opts = opts || {}
if (!(this instanceof Detached)) return new Detached(opts)
Choo.call(this, opts)
this._detached = opts.detached === undefined ? true : opts.detached
if (this._detached) {
this._historyEnabled = false
this._hrefEnabled = false
this.handler = null
this._matchRoute = this._matchRoute.bind(this, '/')
}
}
Detached.prototype = Object.create(Choo.prototype)
Detached.prototype.constructor = Detached
Detached.prototype.component = function (handler) {
assert.notEqual(this._detached, false, 'choo: attempt to mount component in non-detached mode')
assert.equal(typeof handler, 'function', 'choo: handler should be type function')
this.route('/', handler)
}
module.exports = Detached