Skip to content

Commit 3455589

Browse files
committed
Fix(dom schedule): usability bug
When multiply name is used to call schedule(name, ...args) schedule will mess up their arg (stored in one Array<Args>) where type Args = Array<any>
1 parent 47505cf commit 3455589

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

scripts/lib/dom.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Predicate, Consumer, Action } from './util'
22
import { iterableBy, entries } from './util'
3+
import is from './is_test'
34

45
export type ElementConfig = Consumer<Element>
56

@@ -19,13 +20,14 @@ export function waitsElement(e: Element, op: Action) {
1920
}
2021
}
2122

22-
const scheduleQueue: Array<Array<any>> = [];
23+
const scheduleQueues: {[name:string]: Array<Array<any>>} = {};
2324
const schedulePlace: any = (window as any);
2425
export function schedule(name: string, ...args: any) {
26+
let scheduleQueue = scheduleQueues[name];
2527
let found: Function = schedulePlace[name];
26-
if (found != undefined) {
27-
while (scheduleQueue.length != 0) found(...scheduleQueue.shift());
28-
found(...args);
28+
if (is.someValue(found)) {
29+
while (is.notEmpty(scheduleQueue)) found(...scheduleQueue.shift());
30+
/*and then call*/found(...args);
2931
}
3032
else scheduleQueue.push(args);
3133
}

0 commit comments

Comments
 (0)