diff options
author | pragdave <dave@pragdave.me> | 2020-05-07 13:51:16 -0500 |
---|---|---|
committer | pragdave <dave@pragdave.me> | 2020-05-07 13:51:16 -0500 |
commit | d5097965aa2cc2726e241333d8d6d0fa090717eb (patch) | |
tree | 35b57230a852cbaf498654210104fa10d7816564 | |
parent | c8cb22863bf8c3ac157f6098be9154908aea9ec2 (diff) | |
download | svg.js-d5097965aa2cc2726e241333d8d6d0fa090717eb.tar.gz svg.js-d5097965aa2cc2726e241333d8d6d0fa090717eb.zip |
It was difficult to use the zero-parameter form of Timeline.schedule() with TypeScript. The .d.ts file didn't include the retuen type for a list of runner infos, and adding it still m,ade it harder than it should be to iterate over it type safely. In this commit I
1. Added the type information for `ScheduledRunnerInfo`, and updated the Timeline types to include it as a retuen type for `schedule`
2. Added a new function to Timeline, `getSchedule`, that simply returns the runner list. This seems to be cleaner than having the original `schedule` that can return two wildly different things.
I didn't remove the old functionality.
-rw-r--r-- | src/animation/Timeline.js | 9 | ||||
-rw-r--r-- | svg.js.d.ts | 10 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/animation/Timeline.js b/src/animation/Timeline.js index d175ae6..f37cb7a 100644 --- a/src/animation/Timeline.js +++ b/src/animation/Timeline.js @@ -44,10 +44,17 @@ export default class Timeline extends EventTarget { this._stepImmediate = this._stepFn.bind(this, true) } + // returns information on each runner in the timeline. + // (start, duration, end, and runner) + + getSchedule () { + return this._runners.map(makeSchedule) + } + // schedules a runner on the timeline schedule (runner, delay, when) { if (runner == null) { - return this._runners.map(makeSchedule) + return this.getSchedule() } // The start time for the next animation can either be given explicitly, diff --git a/svg.js.d.ts b/svg.js.d.ts index e397e05..02dd6df 100644 --- a/svg.js.d.ts +++ b/svg.js.d.ts @@ -772,11 +772,19 @@ declare module "@svgdotjs/svg.js" { }
// Timeline.js
+ interface ScheduledRunnerInfo {
+ start: number
+ duration: number
+ end: number
+ runner: Runner
+ }
+
class Timeline extends EventTarget {
constructor()
constructor(fn: Function)
- schedule(runner?: Runner, delay?: number, when?: string): this
+ getSchedule(): ScheduledRunnerInfo[]
+ schedule(runner?: Runner, delay?: number, when?: string): ( this | ScheduledRunnerInfo[] )
unschedule(runner: Runner): this
getEndTime(): number
updateTime(): this
|