Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't export default Router.map() #9966

Closed
devinrhode2 opened this issue Dec 18, 2014 · 11 comments
Closed

Can't export default Router.map() #9966

devinrhode2 opened this issue Dec 18, 2014 · 11 comments

Comments

@devinrhode2
Copy link

I searched issues for: Router map return "router:main" - and got no results.
Confirmed on canary here: http://emberjs.jsbin.com/niceculasu/3/

Use case:

import Ember from 'ember';
export default Ember.Router.extend({
  location: config.locationType
}).map(function(){
  this.resource('todos');
});

Error:

Uncaught Error: Failed to create an instance of 'router:main'. Most likely an improperly defined class or an invalid module export.

Expected:
To be able to return the result from Router.map - that is, I expected it to return the Router instance. I think this would be a great API. I would assume Ember supports method chaining on any and every object, I'm (grumpily) curious what else doesn't have straightforward jQuery-like chaining

Disclosure: I actually discovered this error when using ember-cli-coffees6 and documented it all here:https://github.com/devinrhode2/major-domo/issues/1

@wagenet
Copy link
Member

wagenet commented Dec 18, 2014

This should be really easy to PR, though I can't yet guarantee that we'd merge it.

@stefanpenner
Copy link
Member

the result of map, is an instance of router.js router, not ember router.

As such the solution today is: https://github.com/stefanpenner/ember-cli/blob/master/blueprints/app/files/app/router.js#L1-L11

This has to do with the original flexibility of this API design and how chaining off router.js vs ember router.

@wagenet
Copy link
Member

wagenet commented Dec 18, 2014

@stefanpenner any reason not to wrap the map function in Ember.Router to return the Ember version?

@stefanpenner
Copy link
Member

unsure, I suspect it is fine now. It will for sure be fine in 2.x.

I recall there was a reason we couldn't do this around 1.0, but I can't remember exactly what it was.

@stefanpenner
Copy link
Member

just go for it, its so small, leaking inner router is just confusing.

@devinrhode2
Copy link
Author

We could put in a check for this, where would be the best place to put this check and what's the most robust way to check?

I posted on StackOverflow so anyone that searches can find an answer there (https://stackoverflow.com/questions/27539484/ember-js-failed-to-create-an-instance-of-routermain/27539485#27539485)

@stefanpenner
Copy link
Member

We could put in a check for this,

check? I think Router.map should just return this instead of router

@rwjblue
Copy link
Member

rwjblue commented Dec 18, 2014

I agree that it should return the instance of Ember.Router. I've got active work in this area that I am targeting for 1.11 so I can roll this into that effort...

@devinrhode2
Copy link
Author

@rwjblue 👍

@rwjblue
Copy link
Member

rwjblue commented Dec 21, 2014

Will be fixed once #9994 is merged.

@petrvolny
Copy link
Contributor

#9994 is merged. Can this issue be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants