mharris717 / ember-cli-pagination

Pagination Addon for Ember CLI
MIT License
272 stars 116 forks source link

Fix problem with various methods from ArrayProxy #263

Closed synaptiko closed 5 years ago

synaptiko commented 5 years ago

In my case I had following code:

model = EmberObject.create({
  items: findPaged({ ... })
})

...

savedItems: filterBy('items', 'isNew', false)

And it was failing whenever I accessed savedItems.

ArrayProxy implementation changed in Ember 3.x, now it's required to call this._super(...arguments) in init method so the ArrayProxy is properly initialized.

It fixes issues like this:

Uncaught TypeError: Cannot set property 'length' of undefined
    at Class.objectAt (array_proxy.js:131)
    at objectAt (ember-metal.js:1436)
    at Class._emberMetal.Mixin.create._Mixin$create.slice (array.js:230)
    at Class.objsForPage (divide-into-pages.js:11)
    at Class.<anonymous> (paged-array.js:19)
    at ComputedProperty.get (ember-metal.js:2515)
    at _get (ember-metal.js:1356)
    at Class._addArrangedContentArrayObsever (array_proxy.js:164)
    at Class.init (array_proxy.js:102)
    at Class.CoreObject (core_object.js:145)

Fixes #258

broerse commented 5 years ago

Like this but this generates 8 failed test. Can you take a look?

synaptiko commented 5 years ago

Fixed according to docs: https://github.com/emberjs/ember.js/blob/v3.6.1/packages/%40ember/-internals/runtime/lib/system/array_proxy.js#L62-L64

When overriding this class, it is important to place the call to _super after setting content so the internal observers have a chance to fire properly

broerse commented 5 years ago

Thanks! https://github.com/mharris717/ember-cli-pagination/releases/tag/v3.1.4