Skip to content

Commit

Permalink
on and off aliases added
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-gonzalez committed Dec 14, 2018
1 parent c6379d2 commit f005a29
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ timer.addEventListener('secondsUpdated', function (e) {
* Parameters:
* eventType (string): The type of the event that you want to listen.
* callback (function): Function that will be executed when the timer triggers the specified event. The callback receives an object with the timer as a parameter.
* on(eventType, callback): addEventListener alias.
* removeEventListener(eventType, callback): Remove an event listener from the timer. Same usage as addEventListener.
* off(eventType, callback): removeEventListener alias.
* getTimeValues(): Returns an object with the current values. The keys of the returned object are 'secondTenths', 'seconds', 'minutes', 'hours' and 'days'.
* getTotalTimeValues(): Returns an object with the current absolute values. The keys of the returned object are 'secondTenths', 'seconds', 'minutes', 'hours' and 'days'.

Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ declare module "easytimer" {
reset(): void;
pause(): void;
addEventListener(event: Event, listener: () => void): void;
on(event: Event, listener: () => void): void;
removeEventListener(event: Event, listener: () => void): void;
off(event: Event, listener: () => void): void;
dispatchEvent(event: string): void;
isRunning(): boolean;
isPaused(): boolean;
Expand Down
8 changes: 4 additions & 4 deletions src/easytimer/easytimer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
/**
* @license easytimer.js v2.0.0
* Created by Albert González
* Licensed under The MIT License.
*
* @class Timer
*/

Expand Down Expand Up @@ -507,7 +503,11 @@ function Timer () {

this.addEventListener = addEventListener;

this.on = addEventListener;

this.removeEventListener = removeEventListener;

this.off = removeEventListener;
}
};

Expand Down
12 changes: 12 additions & 0 deletions test/timer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,5 +842,17 @@ describe('timer.js', function () {
sinon.assert.callCount(secondsUpdatedListener, 6);
});
});

describe('on function', () => {
it('should be an alias of addEventListener', () => {
assert.equal(timer.addEventListener, timer.on);
});
});

describe('off function', () => {
it('should be an alias of removeEventListener', () => {
assert.equal(timer.removeEventListener, timer.off);
});
});
});
});

0 comments on commit f005a29

Please sign in to comment.