QubitProducts/cherrytree

When using router.handlers getting a TypeError

DavidStrada opened this issue · 4 comments

Hey there :

Context:

router.map(function() {
 this.route("launch", { path: "/launch"});
});`

`router.handlers['launch'] = Route.extend({ before, model,after})`

By doing it this way i get this error Uncaught TypeError: Cannot set property 'launch' of undefined

If i change it to (works):
router.routes["launch"] = Route.extend({});

However I've read the docs and they say the former it's the way to go, also notice you committed the change 2a8a0ca

I'm on version "cherrytree": "^0.5.0", Installed via NPM.
Using Browserify browserify router-amd.js > router.js,

Not sure what's wrong here, also I'm following this tut --> http://requirebin.com/?gist=aa3edb9fb05fa01c59f0#

I've setup an example :
http://requirebin.com/?gist=5e3a07d047285d1d1342

Also notice that data is never being resolved after you return a promise on model.

`router.handlers['post.show'] = Route.extend({
  model: function () {
return $.getJSON('/url');
  },
 activate: function (data) {
// **renders empty obj**  console.log(data)
  }
 });`

Hi. I think the issue is that I kinda was about to release a new version, but never got around doing so.

So the documentation (for version 0.6.0) doesn't match the version that's released to npm (0.5.0).

I'll give you more info soon. Sorry about the confusion.

Hi again. I've released version 0.6.0 to npm. The docs should match that version much better now.

Here's a new working example: http://requirebin.com/?gist=543a9f1a36382683f422.
Requirebin is weird with caching, so you might need to clear the IndexedDB if it's not working since it might be loading the old version of Cherrytree (in Chrome, Dev Tools > Resources > IndexedDB > right click clear).

Regarding returning data in the model - that should also work in 0.6.0 the way you expected.

Also, if you "name" your data it makes it possible to access it in the child routes, e.g.

router.handlers['post.show'] = Route.extend({
  model: function () {
    // the route will only resolve when each value in this returned object resolves
    // this way you can fetch and name multiple things at once
    return {
      someName: $.getJSON('/url')
    };
  },
  activate: function (context) {
    // you can access the named data via this.get in here as well as in all child routes
    console.log(context.someName === this.get("someName"));
  }
 });

Hope this helps. Sorry about the confusion earlier and thanks for reporting the issue!

Hey KidkArolis,

Thanks for resolving the issue :).