Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

How do I do the equivalent of compute.on/compute.off while using can.Map.define?

$
0
0
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:

  1. can.route('pages');
  2. can.route('pages/:page');
  3. can.route('posts');
  4. can.route('posts/:post');
  5. var Router = can.Map.extend({
  6.       define: {
  7.             pages: {
  8.                   serialize: false,
  9.                   value: {},
  10.                   set: function( query, setValue ) {
  11.                        if(/pages$/.test(this.attr('route')) { // Sadly not defined, and doesn't observe changes
  12.                              Page.findAll(query).done(setValue);                        
  13.                         }
  14.                         return null;
  15.                   }
  16.             }
  17.       }
  18. })();
  19. 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.

Viewing all articles
Browse latest Browse all 3491

Trending Articles