0

I want to change the value of two properties of an Ember Component inside a Mixin it extends.

MyMixin = Ember.Mixin.create
  init: ->
    @set 'threshold', undefined
    @set 'oldItems', undefined
    @_super(arguments...)

    itemsLengthObserver: Ember.observer('items.content.length', ->
      actualItems = @get('items.content.length') or 0
      threshold = @get('threshold')
      oldItems = @get('oldItems')
      if actualItems > 0 and not threshold
        @set 'oldItems', actualItems
        @set 'threshold', true
      else
        ....

If I breakpoint after the @set threshold line and check the values for oldItems and threshold I can see the values were properly changed, however next time the items.content.length changes, values appear to be reset to default (both undefined)

Urco
  • 365
  • 3
  • 14
  • Your dependent key should be `items.[]`, is the content property an array you are setting? – Patsy Issa Mar 04 '16 at 08:55
  • Possible duplicate of [Ember.js 2.3 implement @each.property observer on a HasMany relationship?](http://stackoverflow.com/questions/35689841/ember-js-2-3-implement-each-property-observer-on-a-hasmany-relationship) – Patsy Issa Mar 04 '16 at 08:55
  • I changed route and when come back to the component properties were gone. I could not avoid that route transition so I had to work around it with other solution. – Urco Mar 04 '16 at 13:01
  • If you want to persist your items across routes use a [service](https://guides.emberjs.com/v2.4.0/applications/services/) – Patsy Issa Mar 04 '16 at 13:02

0 Answers0