mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
chore(DomController): updates
This commit is contained in:
@ -12,14 +12,14 @@ export class DomController {
|
|||||||
private w: Function[] = [];
|
private w: Function[] = [];
|
||||||
private q: boolean;
|
private q: boolean;
|
||||||
|
|
||||||
read(fn: Function, ctx?: any): Function {
|
read(fn: {(timeStamp: number)}, ctx?: any): Function {
|
||||||
const task = !ctx ? fn : fn.bind(ctx);
|
const task = !ctx ? fn : fn.bind(ctx);
|
||||||
this.r.push(task);
|
this.r.push(task);
|
||||||
this.queue();
|
this.queue();
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
write(fn: Function, ctx?: any): Function {
|
write(fn: {(timeStamp: number)}, ctx?: any): Function {
|
||||||
const task = !ctx ? fn : fn.bind(ctx);
|
const task = !ctx ? fn : fn.bind(ctx);
|
||||||
this.w.push(task);
|
this.w.push(task);
|
||||||
this.queue();
|
this.queue();
|
||||||
@ -30,28 +30,29 @@ export class DomController {
|
|||||||
return removeArrayItem(this.r, task) || removeArrayItem(this.w, task);
|
return removeArrayItem(this.r, task) || removeArrayItem(this.w, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
private queue() {
|
protected queue() {
|
||||||
if (!this.q) {
|
const self = this;
|
||||||
this.q = true;
|
if (!self.q) {
|
||||||
nativeRaf(timestamp => {
|
self.q = true;
|
||||||
this.flush(timestamp);
|
nativeRaf(function rafCallback(timeStamp) {
|
||||||
|
self.flush(timeStamp);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private flush(timestamp: number) {
|
protected flush(timeStamp: number) {
|
||||||
let err;
|
let err;
|
||||||
let task;
|
let task;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// ******** DOM READS ****************
|
// ******** DOM READS ****************
|
||||||
while (task = this.r.shift()) {
|
while (task = this.r.shift()) {
|
||||||
task(timestamp);
|
task(timeStamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ******** DOM WRITES ****************
|
// ******** DOM WRITES ****************
|
||||||
while (task = this.w.shift()) {
|
while (task = this.w.shift()) {
|
||||||
task(timestamp);
|
task(timeStamp);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
err = e;
|
err = e;
|
||||||
|
Reference in New Issue
Block a user