Skip to content

Commit

Permalink
fix: unsubscribe from decorator when the object is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlafroscia committed Feb 5, 2019
1 parent e96d160 commit 1abd5fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion addon/decorators/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function subscribe(observableKey) {
}

willDestroy() {
this.removeListener(observableKey, this, resetSubscription);
this.removeObserver(observableKey, this, resetSubscription);

if (this[SUBSCRIPTION]) {
this[SUBSCRIPTION].unsubscribe();
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/decorators/subscribe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,26 @@ module("Unit | Decorator | subscribe", function(hooks) {
);
});
});

test("it un-subscribes when the object is destroyed", function(assert) {
this.scheduler.run(helpers => {
const i = SomeClass.create({
observable: helpers.cold("--a--b", {
a: 1,
b: 2
})
});

this.scheduler.flush();

i.willDestroy();

assert.equal(
i.observable.subscriptions[0].unsubscribedFrame,
5,
"Unsubscribed from the observable"
);
});
});
});
});

0 comments on commit 1abd5fb

Please sign in to comment.