chore(DomController): updates

This commit is contained in:
Adam Bradley
2016-12-01 08:59:18 -06:00
parent 7b2a6d523e
commit 0b642e7e96

View File

@ -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;