Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Commit

Permalink
Bump version
Browse files Browse the repository at this point in the history
- add `route` binding for dealing with dynamic base paths
  • Loading branch information
caseyWebb committed Aug 13, 2015
1 parent f0a4c41 commit 852b97b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
2 changes: 1 addition & 1 deletion bower.json
@@ -1,7 +1,7 @@
{
"name": "ko-component-router",
"main": "ko-component-router.js",
"version": "2.0.1",
"version": "2.1.0",
"homepage": "https://github.com/caseyWebb/ko-component-router",
"repository": {
"type": "git",
Expand Down
56 changes: 41 additions & 15 deletions ko-component-router.js
Expand Up @@ -929,42 +929,68 @@ var ko = require('knockout')

ko.router = require('./lib/router')

},{"./lib/router":7,"knockout":"knockout"}],6:[function(require,module,exports){
},{"./lib/router":8,"knockout":"knockout"}],6:[function(require,module,exports){
'use strict'

var ko = require('knockout')

var router = require('./router')

ko.bindingHandlers.route = {
init: function(el, valueAccessor) {
ko.applyBindingsToNode(el, {
attr: {
href: ko.pureComputed(function() {
return router._basePath + ko.unwrap(valueAccessor())
})
}
})
}
}

},{"./router":8,"knockout":"knockout"}],7:[function(require,module,exports){
'use strict'

var ko = require('knockout')

var router = require('./router')

function ViewModel() {
this.component = router._component
this.ctx = router._ctx
}

ko.components.register('ko-component-router', {
viewModel: function ViewModel() {
this.component = router.component
this.ctx = router.ctx
},
viewModel: ViewModel,
template: "<div data-bind='component: {" +
"name: component," +
"params: ctx" +
"}'></div>"
})

},{"./router":7,"knockout":"knockout"}],7:[function(require,module,exports){
module.exports = ViewModel

},{"./router":8,"knockout":"knockout"}],8:[function(require,module,exports){
'use strict'

var ko = require('knockout')
var page = require('page')

function Router() {
this.component = ko.observable()
this.ctx = ko.observable()
this._component = ko.observable()
this._ctx = ko.observable()
}

Router.prototype.start = function(config) {
if (config.basePath) {
page.base(config.basePath)
}
if (typeof config === 'undefined')
config = {}

this._basePath = config.basePath || ''

page.base(this._basePath)
page.start(config)

require('./binding')
require('./component')
}

Expand Down Expand Up @@ -1004,10 +1030,10 @@ Router.prototype.route = function(route) {

page.apply(page, args)

function getComponentSetter(_el) {
function getComponentSetter(component) {
return function(ctx, next) {
self.component(_el)
self.ctx(ctx)
self._component(component)
self._ctx(ctx)
ctx.handled = true
next()
}
Expand All @@ -1016,5 +1042,5 @@ Router.prototype.route = function(route) {

module.exports = new Router()

},{"./component":6,"knockout":"knockout","page":2}]},{},[5])(5)
},{"./binding":6,"./component":7,"knockout":"knockout","page":2}]},{},[5])(5)
});

0 comments on commit 852b97b

Please sign in to comment.