This sounds like it could be very useful for newcomers to Kanso. I'll
be happy to review it once you find a place to share it. As John says,
GitHub would be ideal, it provides some nice tools for commenting on
code and sharing changes.
Thanks!
Caolan
I think you'll find much more interest if you're able to provide a
link to the app on GitHub. It would make it a lot easier to browse the
code and discuss. If you'd like to post it on there, but need some
help getting it uploaded, feel free to contact me on GTalk or IRC
(caolanm on FreeNode) and I'll be happy to help.
Caolan
Firstly, the server (couchdb) renders a static HTML page and delivers
it to the browser. Then, the commonjs environment is loaded
client-side and an 'init' event is fired (the event you are
subscribing to). This is a good time to bind event handlers to parts
of the base.html template not going to be replaced when you update the
content div.
Next, the init event triggers URL handling by Kanso. It will attempt
to match the original request to the correct show / list / update
function and will *re-render* it client-side. That usually means the
content div will be replaced with this new content, blowing away any
event handlers you might have bound to HTML elements already in there
during 'init'.
The 'afterResponse' event is probably what you're looking for. Though
you'll want to just bind to it once inside the show / list / update
function:
exports.myShow = function (doc, req) {
events.once('afterResponse', function (info, req, res) {
// bind event handlers
});
return {
title: 'myPage',
content: templates.render(...)
}
};
This ensures they are re-bound when the page is rendered again and the
elements are replaced. Using 'event.once' just means the event will
fire the next time the event is emitted and then be unbound.
So the rule is probably something like this:
- If it is in base.html, not inside the 'content' div, and will never
change, use the 'init' event to bind event handlers
- If it is going to change depending on the page, and is probably
inside the 'content' div, use the 'afterResponse' event inside you
show / list / update function
Hope that helps, if I've misdiagnosed the issue just let me know.
Keep up the good work! :)
Caolan
If you could add some information on getting Kanso running on Cygwin
to the wiki (http://kan.so/docs), I'm sure some Windows users will
really appreciate it.
Caolan
I'm afraid Duality isn't particularly well documented at the moment.
Unless you need server-side rendering of pages I'd recommend using one
of the other popular frameworks like Backbone or Spine. Good
documentation is a major aim for this project, but because it can be
used in so many ways its difficult to get everything documented
straight away ;)
As for my commitment to Kanso, I make my living consulting on Kanso
projects so there is at least me and the teams I work with having
financial and strategic incentives to keep this project up to date.
This project has been evolving for around a year and will continue to
do so, there are plenty of exciting ideas in this space to keep us
interested!
Caolan