]> source.dussan.org Git - svg.js.git/commitdiff
It was difficult to use the zero-parameter form of Timeline.schedule() with TypeScrip...
authorpragdave <dave@pragdave.me>
Thu, 7 May 2020 18:51:16 +0000 (13:51 -0500)
committerpragdave <dave@pragdave.me>
Thu, 7 May 2020 18:51:16 +0000 (13:51 -0500)
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.

src/animation/Timeline.js
svg.js.d.ts

index d175ae6d60597e8deff8ed14ea37a0c760d19cbf..f37cb7a6238e9b8dfa0534924b5cc10bcf163176 100644 (file)
@@ -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,
index e397e0553dc825685ad1a0dd56e6dfede22ab815..02dd6df855b996f74a2cc6e4684d4f5eb66b890b 100644 (file)
@@ -772,11 +772,19 @@ declare module "@svgdotjs/svg.js" {
     }\r
 \r
     // Timeline.js\r
+    interface ScheduledRunnerInfo {\r
+        start: number\r
+        duration: number\r
+        end: number\r
+        runner: Runner\r
+    }\r
+\r
     class Timeline extends EventTarget {\r
         constructor()\r
         constructor(fn: Function)\r
 \r
-        schedule(runner?: Runner, delay?: number, when?: string): this\r
+        getSchedule(): ScheduledRunnerInfo[]\r
+        schedule(runner?: Runner, delay?: number, when?: string): ( this | ScheduledRunnerInfo[] )\r
         unschedule(runner: Runner): this\r
         getEndTime(): number\r
         updateTime(): this\r