Skip to content

Commit

Permalink
Set current state
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Aug 9, 2012
1 parent 8b8445f commit d0bebac
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions index.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ko.routes = (mapping)->
Routes = -> Routes = ->
Routes.prototype = {} Routes.prototype = {}


current_url = ko.observable() current = ko.observable()
routes = new Routes routes = new Routes


for own name, route of mapping when typeof route == 'string' for own name, route of mapping when typeof route == 'string'
Expand All @@ -37,7 +37,7 @@ ko.routes = (mapping)->
u = u.replace(suid, '') u = u.replace(suid, '')
matches = u.match(regexp) matches = u.match(regexp)
if matches if matches
current_url url() current state
unless data unless data
data = {} data = {}
data[names[i]] = value for value, i in matches.slice(1) data[names[i]] = value for value, i in matches.slice(1)
Expand All @@ -61,11 +61,12 @@ ko.routes = (mapping)->


state.url = url state.url = url
state.param = params state.param = params
state.active = ko.computed read: -> url() == current_url() state.active = ko.computed read: -> url() == current().url()


routes[name] = state routes[name] = state
)(name, route) )(name, route)


Routes.prototype.current = current
Routes.prototype.ready = (_sigil)-> Routes.prototype.ready = (_sigil)->
sigil _sigil if _sigil sigil _sigil if _sigil
state = History.getState() state = History.getState()
Expand Down
9 changes: 5 additions & 4 deletions knockout-routes.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion knockout-routes.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d0bebac

Please sign in to comment.