GithubHelp home page GithubHelp logo

Comments (9)

asross avatar asross commented on August 21, 2024

Hmm, can you give an example in code? If there is an update to the component's params.className or className to "some-class-name active" instead of just "some-class-name", it should update the link's HTML.

If not, it's possible there's an issue in how I'm overriding className though, or that I'm somehow making it impossible to pass additional class names. If you can provide just a few more details then I should be able to replicate the issue in a test and implement a fix.

from dynamic-link.

jrdn91 avatar jrdn91 commented on August 21, 2024

This is how I tried it className: this.get('filteringLosing') ? "filter-losing active" : "filter-losing"

from dynamic-link.

asross avatar asross commented on August 21, 2024

This is how I tried it className: this.get('filteringLosing') ? "filter-losing active" : "filter-losing"

Can you give more context? That doesn't look like a computed property to me, and also where are you putting that logic? Is it in a controller or component whose template invokes dynamic-link?

from dynamic-link.

jrdn91 avatar jrdn91 commented on August 21, 2024

In the route I am setting an array of navigation items like so

this.get('navigation').set('actionBarItems',[
    Ember.Object.create({
        linkParams:  {
            action: "losingItems",
            className: this.get('filteringLosing') ? "filter-losing active" : "filter-losing"
        },
        icon: "noun_245219_cc"
      }),
    Ember.Object.create({
       linkParams:  {
            action: "winningItems",
            className: "filter-winning"
        },
        icon: "trophy"
    }),
    Ember.Object.create({
        linkParams:  {
            action: "watchingItems",
            className: "filter-watching"
        },
        icon: "noun_197397_cc"
    })
]);

I also have a property filteringLosing: false, in an action I toggle this property so that it's now true

this.toggleProperty('filteringLosing');

Where my navigation is I call dynamic-link like

{{#dynamic-link params=linkParams}}
    ...
{{/dynamic-link}}

from dynamic-link.

asross avatar asross commented on August 21, 2024

Ah, well it looks like the problem is that actionBarItems isn't a computed property, so it won't update when filteringLosing changes.

One option is to restructure your code so that your navigation takes a computed property, which would depend on filteringLosing, e.g.:

actionBarItems: Ember.computed('filteringLosing', function() {
  return [{
      linkParams:  {
          action: "losingItems",
          className: this.get('filteringLosing') ? "filter-losing active" : "filter-losing"
      },
      icon: "noun_245219_cc"
  }, {
       // rest of your action bar items
  }];
})

But I don't know how the rest of your code is structured, so I can't say exactly how you would do this.

Another option is to update navigation.actionBarItems using an observer whenever filteringLosing changes, which might look like:

updateNavigation: Ember.on('init', Ember.observer('filteringLosing', function() {
  this.get('navigation').set('actionBarItems',[
      Ember.Object.create({
          linkParams:  {
              action: "losingItems",
              className: this.get('filteringLosing') ? "filter-losing active" : "filter-losing"
          },
          icon: "noun_245219_cc"
        }),
      Ember.Object.create({
         linkParams:  {
              action: "winningItems",
              className: "filter-winning"
          },
          icon: "trophy"
      }),
      Ember.Object.create({
          linkParams:  {
              action: "watchingItems",
              className: "filter-watching"
          },
          icon: "noun_197397_cc"
      })
  ]);
}))

That function will re-trigger every time filteringLosing changes, so the link should hopefully update too.

from dynamic-link.

jrdn91 avatar jrdn91 commented on August 21, 2024

I'm also noticing when a property changes and I have the model set to the value of that property the links are not being updated on page to point to the new link with the updated model based on the property that changed.

Basically in the same vein as this above class issue as it seems when that property changes it doesn't update the class, this is happening also in the model definition.

from dynamic-link.

asross avatar asross commented on August 21, 2024

I'm also noticing when a property changes and I have the model set to the value of that property the links are not being updated on page to point to the new link with the updated model based on the property that changed.

Basically in the same vein as this above class issue as it seems when that property changes it doesn't update the class, this is happening also in the model definition.

Again, from what you've showed me so far this doesn't seem to be an issue with dynamic-link; instead it looks like you're setting actionBarItems without any data bindings, so none of the updates ever propagate to navigation, much less any links it renders.

from dynamic-link.

asross avatar asross commented on August 21, 2024

If it's helpful, the pattern I used to get this type of behavior (where you have a bar of links that's present on multiple routes but should be different for each) is to have a named outlet in my application template for the action bar:

{{! application.hbs }}

{{ outlet "action-bar" }}

Then a partial with my action bar:

{{! -action-bar.hbs }}

{{#if actionBarItems}}
  <ul class='action-bar'>
     {{#each actionBarItems as |actionBarItem|}} 
        <li class='action-bar-item'>
          {{#dynamic-link params=actionBarItem.linkParams}}
             {{actionBarItem.linkText}}
          {{/dynamic-link}}
        </li>
     {{/each}}
  </ul>
{{/if}}

And then I have a mixin I include in some routes which renders an action bar template:

// app/mixins/action-bar-route.js
export default Ember.Mixin.extend({
  renderTemplate: function(controller, model) {
     this.render('action-bar', { into: 'application', outlet: 'action-bar' });
     this._super(controller, model);
  }
});

// app/routes/some-resource.js
import ActionBarRouteMixin from '../mixins/action-bar-route';
export default Ember.Route.extend(ActionBarRouteMixin, {
  // some code
});

At that point, for a route where I want the action bar, I just include the mixin and define actionBarItems as a computed property on its controller:

// app/controllers/some-resource.js
export default Ember.Controller.extend({
  actionBarItems: Ember.computed('model.name', 'filteringLosing', function() {
    return [
      // some list of items that depend on some of my properties
    ];
  });
});

That pattern has worked pretty well for me with dynamic-link.

from dynamic-link.

asross avatar asross commented on August 21, 2024

Going to close this now since it seems like it's not a problem with dynamic-link.

from dynamic-link.

Related Issues (5)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.