diff --git a/README.md b/README.md index b68089b..e14b44e 100644 --- a/README.md +++ b/README.md @@ -48,14 +48,12 @@ const animate = new Animate({ easing: Easing.easeInOutQuad, }); -// Attach event listeners -animate.on('start', () => console.log('Animation Start')); -animate.on('update', value => console.log('Animation Update:', value)); -animate.on('complete', () => console.log('Animation Complete')); -animate.on('stop', () => console.log('Animation Stop')); - -// Start the animation -animate.start(); +animate + .on('start', () => console.log('Animation Start')) + .on('update', value => console.log('Animation Update:', value)) + .on('complete', () => console.log('Animation Complete')) + .on('stop', () => console.log('Animation Stop')) + .start(); ``` ### Sequence of Animations @@ -82,13 +80,12 @@ const animate2 = new Animate({ const sequence = new Sequence({ items: [animate1, animate2] }); // Attach event listeners -sequence.on('start', () => console.log('Sequence Start')); -sequence.on('update', value => console.log('Sequence Update:', value)); -sequence.on('complete', () => console.log('Sequence Complete')); -sequence.on('stop', () => console.log('Sequence Stop')); - -// Start the sequence -sequence.start(); +sequence + .on('start', () => console.log('Sequence Start')) + .on('update', value => console.log('Sequence Update:', value)) + .on('complete', () => console.log('Sequence Complete')) + .on('stop', () => console.log('Sequence Stop')) + .start(); ``` ### Parallel Sequences @@ -125,10 +122,11 @@ const sequence1 = new Sequence({ items: [animate1, animate2] }); const parallelSequence = new Sequence({ items: [sequence1, animate3], parallel: true }); // Attach event listeners -parallelSequence.on('start', () => console.log('Parallel Sequence Start')); -parallelSequence.on('update', value => console.log('Parallel Sequence Update:', value)); -parallelSequence.on('complete', () => console.log('Parallel Sequence Complete')); -parallelSequence.on('stop', () => console.log('Parallel Sequence Stop')); +parallelSequence + .on('start', () => console.log('Parallel Sequence Start')) + .on('update', value => console.log('Parallel Sequence Update:', value)) + .on('complete', () => console.log('Parallel Sequence Complete')) + .on('stop', () => console.log('Parallel Sequence Stop')); // Start the sequence parallelSequence.start(); diff --git a/package-lock.json b/package-lock.json index e1518a4..13b428e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "events": "^3.3.0", + "eventemitter3": "^5.0.1", "ts-easing": "^0.2.0" }, "devDependencies": { @@ -2363,13 +2363,10 @@ "node": ">=0.10.0" } }, - "node_modules/events": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz", - "integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==", - "engines": { - "node": ">=0.8.x" - } + "node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==" }, "node_modules/execa": { "version": "5.1.1", diff --git a/package.json b/package.json index 1db736c..8c3bee4 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "author": "Donal Linehan", "license": "MIT", "dependencies": { - "events": "^3.3.0", + "eventemitter3": "^5.0.1", "ts-easing": "^0.2.0" }, "devDependencies": { diff --git a/src/animate.ts b/src/animate.ts index a642791..fb86ad9 100644 --- a/src/animate.ts +++ b/src/animate.ts @@ -1,4 +1,4 @@ -import { EventEmitter } from 'events'; +import EventEmitter from 'eventemitter3'; import { TEasing } from 'ts-easing'; import { easing as e } from './easing'; @@ -96,6 +96,7 @@ export class Animate extends EventEmitter { this.startTime = performance.now(); this.emit('start'); this.requestId = requestAnimationFrame(this.tick); + return this; } public stop() { @@ -103,5 +104,6 @@ export class Animate extends EventEmitter { cancelAnimationFrame(this.requestId); this.emit('stop'); } + return this; } } diff --git a/src/sequence.ts b/src/sequence.ts index 25c3094..44c40c2 100644 --- a/src/sequence.ts +++ b/src/sequence.ts @@ -1,4 +1,4 @@ -import { EventEmitter } from 'events'; +import EventEmitter from 'eventemitter3'; import { Animate, AnimatableValue } from './animate'; type SequenceItem = Animate | Sequence; @@ -64,6 +64,7 @@ export class Sequence extends EventEmitter { this.activeAnimates = 0; this.emit('start'); this.next(); + return this; } public stop() { @@ -75,5 +76,6 @@ export class Sequence extends EventEmitter { } }); this.emit('stop'); + return this; } }