[IMP] component: refactor rendering pipeline

This commit introduces a brand new rendering system based on a fiber
class and a scheduler.

closes #330
This commit is contained in:
Aaron Bohy
2019-10-25 15:45:56 +02:00
committed by Géry Debongnie
parent 2bed1cfbd1
commit 9c5cad15c1
24 changed files with 2296 additions and 1320 deletions
+50
View File
@@ -0,0 +1,50 @@
import { Fiber } from "./fiber";
// scheduler
interface Task {
fiber: Fiber;
callback: () => void;
}
export const scheduler = {
tasks: [] as Task[],
isRunning: false,
addFiber(fiber, callback) {
this.tasks.push({ fiber, callback });
if (this.isRunning) {
return;
}
this.scheduleTasks();
},
flush() {
let tasks = this.tasks;
this.tasks = [];
tasks = tasks.filter(task => {
if (task.fiber.isCancelled) {
return false;
}
if (task.fiber.counter === 0) {
task.callback();
return false;
}
return true;
});
this.tasks = tasks.concat(this.tasks);
},
processTasks() {
this.flush();
if (this.tasks.length > 0) {
this.scheduleTasks();
} else {
this.isRunning = false;
}
},
scheduleTasks() {
this.isRunning = true;
this.requestAnimationFrame(() => this.processTasks());
},
requestAnimationFrame: requestAnimationFrame.bind(window)
};