Hi guys,
I'm trying to make a can.route.map that is able to bind to changes in the route and update itself. Essentially, I'd like to do this:
- can.route('pages');
- can.route('pages/:page');
- can.route('posts');
- can.route('posts/:post');
- var Router = can.Map.extend({
- define: {
- pages: {
- serialize: false,
- value: {},
- set: function( query, setValue ) {
- if(/pages$/.test(this.attr('route')) { // Sadly not defined, and doesn't observe changes
- Page.findAll(query).done(setValue);
- }
- return null;
- }
- }
- }
- })();
- can.route.map(Router);
It doesn't look like there's a way to bind to changes with define, and it just using a compute doesn't have the same fine grained control. It would be cool if there were a way to leverage on/off, or otherwise setup change bindings. I already tried using a compute within set to call setValue on changes, however that didn't trigger on changes.