Skip to content

Commit

Permalink
Keep listening for infinityModel changes after hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
DuBistKomisch committed Apr 30, 2020
1 parent 712ec22 commit 2c20935
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 18 deletions.
38 changes: 21 additions & 17 deletions addon/components/infinity-loader.js
Expand Up @@ -80,6 +80,20 @@ const InfinityLoaderComponent = Component.extend({
return 'infinity-loader '.concat(this.classNames).trim();
}),

init() {
this._super(...arguments);

defineProperty(this, 'infinityModelContent', computed('infinityModel', function() {
return Promise.resolve(this.infinityModel);
}));

this.addObserver('infinityModel', this, this._initialInfinityModelSetup);
this._initialInfinityModelSetup();

this.addObserver('hideOnInfinity', this, this._loadStatusDidChange);
this.addObserver('reachedInfinity', this, this._loadStatusDidChange);
},

/**
* setup ember-in-viewport properties
*
Expand All @@ -99,16 +113,6 @@ const InfinityLoaderComponent = Component.extend({

instance.elem = element;

defineProperty(instance, 'infinityModelContent', computed('infinityModel', function() {
return Promise.resolve(instance.infinityModel);
}));

instance.addObserver('infinityModel', instance, instance._initialInfinityModelSetup);
instance._initialInfinityModelSetup();

instance.addObserver('hideOnInfinity', instance, instance._loadStatusDidChange);
instance.addObserver('reachedInfinity', instance, instance._loadStatusDidChange);

let options = {
viewportSpy: true,
viewportTolerance: {
Expand All @@ -125,17 +129,17 @@ const InfinityLoaderComponent = Component.extend({
onExit(instance.didExitViewport.bind(instance));
},

willDestroyLoader(_element, [instance]) {
instance._cancelTimers();
willDestroy() {
this._cancelTimers();

get(instance, 'infinityModelContent')
get(this, 'infinityModelContent')
.then((infinityModel) => {
infinityModel.off('infinityModelLoaded', instance, instance._loadStatusDidChange.bind(instance));
infinityModel.off('infinityModelLoaded', this, this._loadStatusDidChange.bind(this));
});

instance.removeObserver('infinityModel', instance, instance._initialInfinityModelSetup);
instance.removeObserver('hideOnInfinity', instance, instance._loadStatusDidChange);
instance.removeObserver('reachedInfinity', instance, instance._loadStatusDidChange);
this.removeObserver('infinityModel', this, this._initialInfinityModelSetup);
this.removeObserver('hideOnInfinity', this, this._loadStatusDidChange);
this.removeObserver('reachedInfinity', this, this._loadStatusDidChange);
},

/**
Expand Down
1 change: 0 additions & 1 deletion addon/templates/components/infinity-loader.hbs
@@ -1,7 +1,6 @@
{{#if this.isVisible}}
<div
{{did-insert this.didInsertLoader this}}
{{will-destroy this.willDestroyLoader this}}
class="{{this.loaderClassNames}}{{if this.viewportEntered " in-viewport"}}{{if this.isDoneLoading " reached-infinity"}}"
data-test-infinity-loader>

Expand Down

0 comments on commit 2c20935

Please sign in to comment.