chrisfarber / ember-breadcrumbs

An Ember.js component for adding breadcrumbs to your app.
MIT License
79 stars 34 forks source link

Extra crumbs added when controller breadCrumb value changes #49

Open andy-berry-dev opened 7 years ago

andy-berry-dev commented 7 years ago

If the controller's breadCrumb computed property changes, each intermediate value is added to the list of breadcrumbs. This only happens if the controller also has a breadCrumbs property.

screen shot 2017-04-06 at 10 33 51

This is caused by the crumbs.push({...}) at https://github.com/chrisfarber/ember-breadcrumbs/blob/master/addon/components/bread-crumbs.js#L45 since it's pushing on to the array returned by breadCrumbs instead of a copy.

I fixed this locally by copying the array returned by breadCrumbs using slice.

var controllerCrumbs = controller.get("breadCrumbs");
var crumbs = Ember.isArray(controllerCrumbs) ? controllerCrumbs.slice() : Ember.A([]);
var singleCrumb = controller.get("breadCrumb");
chrisfarber commented 7 years ago

That's quite an embarrassing mistake. Thanks for pointing this out to me.