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

isActive not taking context object into consideration #4

Open
balinterdi opened this issue Aug 3, 2017 · 2 comments
Open

isActive not taking context object into consideration #4

balinterdi opened this issue Aug 3, 2017 · 2 comments

Comments

@balinterdi
Copy link

balinterdi commented Aug 3, 2017

I have the following code where I wanted to replace link-to with ember-href-to and using the router service to calculate the active class:

{{#each model as |band|}}
  <a href={{href-to 'bands.band.songs' band.id}}
     class="list-group-item band-link {{if (is-active 'bands.band.songs' band.id) 'active'}}">
    {{band.name}}
    <span class="pointer glyphicon glyphicon-chevron-right"></span>
  </a>
{{/each}}
// app/helpers/is-active.js
import Ember from 'ember';

const { Helper, inject } = Ember;

export default Helper.extend({
  router: inject.service(),

  compute([value, ...models]) {
    return this.get('router').isActive(value, models);
  }
});

The problem I encountered is that all the links are active independently of the actual context object used. In other words, no matter which band link is transitioned to, is-active returns true for all of the links in the list:

screen shot 2017-08-03 at 9 27 04

I drilled down into the code to see what causes this and I've found that the router service polyfill calls the router's isActiveIntent method, which in turn calls NamedTransitionIntent.applyToHandlers (see here) to decide if the link generated is an active one.

However, NamedTransitionIntent.applyToHandlers clobbers the context by copying one context
over the other (see here), and will subsequently find that the handlers are equal and thus return true for isActiveIntent.

I also checked that link-to works fine for this scenario, very probably because it uses another code path to determine if a link is active.

The code I tested this with can be found on the router-service branch of balinterdi/rarwe-demo.

@NickChristensen
Copy link

Just ran into this same thing. In the meantime, is there even a hacky way to get a reference to the current model(s) for that route?

@balinterdi
Copy link
Author

Not that I know of.

  1. this.modelFor(routeName) only works for parent routes of the current route.
  2. There might be a way to imitate what link-to does to see if a route is active (I assume that's why you want to get the current model for that route, too), but it seems to use a fair amount of private APIs (which is what the router service would solve).

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

2 participants