mirror of
https://codeberg.org/vlw/monkeydo.git
synced 2025-09-13 15:53:40 +02:00
Multithreaded web animations and task chaining. Cue JavaScript methods with greater performance and portability using Web Workers and JSON.
|
||
---|---|---|
monkey | ||
.gitignore | ||
LICENSE | ||
Monkeydo.mjs | ||
README.md |
Threaded task chaining for JavaScript
Monkeydo uses the portable data format JSON to read tasks, making it easy to read by primates and machines alike.
{
"tasks": [
[0,"myJavaSriptMethod","someArgument","anotherArgument"]
]
}
|
|
Use Monkeydo
Monkeydo comes as an importable ECMAScript 6 module. In this guide we'll import this directly from a ./modules/ folder, but any web-accesible location will work.
- Import
Monkeydo
as an ES6 moduleimport { default as Monkeydo } from "./modules/Monkeydo/Monkeydo.mjs";
- Define your JS methods in an object
const methods = { myJavaScriptMethod: (foo,bar) => { console.log(foo,bar); } }
- Define your tasks in a JSON manifest (file or JSON-compatible JavaScript)
{ "tasks": [ [0,"myJavaSriptMethod","Just like a","monkey"], [1200,"myJavaSriptMethod","I've been","dancing"], [160,"myJavaSriptMethod","my whole","life"] ] }
- Initialize and run
Monkeydo
with your methods and manifestconst monkey = new Monkeydo(methods); monkey.play(manifest);
The example above would be the same as running:
console.log("Just like a","monkey"); // Right away
console.log("I've been","dancing"); // 1.2 seconds after the first
console.log("my whole","life"); // and then 160 milliseconds after the second