I've just with CanJS so this is probably a simple questiong. I haven an API that has these paths and responses:
- /api/:owner/:repo
- [{commit: '4asd56f4asd56f4asd65f', message: 'Commit message 1'}, {commit: 'df4saf54d6safd54asf6', message: 'Commit message 2'}]
- /api/:owner/:repo/:commit
- {commit_id: '4asd56f4asd56f4asd65f', message: 'Commit message 1', author: 'Frank'}
For this I have a Model:
- findAll: 'GET /api/github/{owner}/{repo}'
- findOne: 'GET /api/github/{owner}/{repo}/{commit}'
Now I want to show this data depending on the URL (e.g. /frk/repo1/ shows a list of commits, /frk/repo1/4asd56f4asd56f4asd65f shows details about one commit).
I have an app state object where I define a get function for 'commits' based on the owner and repo:
- commits: {
get: () ->
new Commit.List {
owner: this.attr('owner')
repo: this.attr('repo')
}
The template for the repo prints a list of commits with links to the
commits themselves. This works great so far, I get a list of commits,
when I clock on a link I listen for the route event in a Commits
component and change the template that is shown to:
- events: {
"/:owner/:repo/:commit route": (data) ->
$('#app').html(can.view('views/commit.mustache', {}))
}
How do I load the details for a single commit? Is it best to add
this to the app state similar to the commits definition? Do I call the
findOne function manually, and how do I return the correct value?
- commitDetails:
{
get: () ->
Commit.findOne {
owner: this.attr('owner')
repo: this.attr('repo')
commit: this.attr('commit')
}
}
I'm sure there is a simple answer for this, but I haven't found any
example and from the docs I can't see the best way to do this. Thanks
in advance :).