https://github.com/nmuldavin/batch
https://github.com/nmuldavin/batch
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/nmuldavin/batch
- Owner: nmuldavin
- Created: 2016-09-11T20:37:51.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-09-13T02:43:35.000Z (almost 10 years ago)
- Last Synced: 2025-02-22T02:41:21.151Z (over 1 year ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#batch.js
batch.js provides a class for queueing actions to be executed before requesting a new animation frame.
### Normal Use
To use, intialize a new Batch instance with ``const batch = new Batch()``. Actions can be added to the batch queue via two methods:
* ``batch.queue(fn)``: Immediately adds an action to the queue. Action must be parameterless:
```
batch.queue(() => {
console.log("I executed");
});
```
* ``batch.add(fn)``: Returns a method that adds the specified function to the queue when called. Any arguments passed to this method will be applied to the original function when executed:
```
batch.add((message) => {
console.log(message);
})("This is my message");
```
To execute all queued actions and request a new animation frame, call ``batch.request_frame()``;
### Synchronous Mode
The batch class may be used in synchronous mode by passing an optional boolean value to the constructor: ``const syncBatch = new Batch(true)`` or by setting ``batch.sync = true``. In synchronous mode, ``request_frame()`` is called immediately when new actions are added to the queue.
### Other methods
To manually execute all queue actions without requesting a new animation frame, call ``batch.run()``.
### Issues
See code commenting for potential issues.