Skip to content

Commit

Permalink
Use registerDestructor instead of willDestroy (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
lozjackson authored May 11, 2024
1 parent cc2694d commit 359de11
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 15 deletions.
11 changes: 2 additions & 9 deletions addon/services/clock.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import Service from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { cancel, later } from '@ember/runloop';
import { registerDestructor } from '@ember/destroyable';

/**
* ## ClockService
Expand Down Expand Up @@ -58,6 +59,7 @@ export default class ClockService extends Service {
constructor() {
super(...arguments);
this.start();
registerDestructor(this, () => this.stop());
}

/**
Expand Down Expand Up @@ -103,13 +105,4 @@ export default class ClockService extends Service {
}
this.nextTick = later(this, this.tick, 1000);
}

/**
call `stop()`
@event willDestroy
@private
*/
willDestroy() {
this.stop();
}
}
6 changes: 0 additions & 6 deletions tests/unit/services/clock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,4 @@ module('Unit | Service | clock', function (hooks) {

assert.true(setTimeStub.calledOnce, 'setTime was called once');
});

test('willDestroy', function (assert) {
const clock = this.owner.lookup('service:clock');
clock.willDestroy();
assert.strictEqual(clock.nextTick, null);
});
});

0 comments on commit 359de11

Please sign in to comment.