1.1.0 • Published 10 years ago

cycl v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
10 years ago

Cycl

A 1.5kb process manager running on a single requestAnimationFrame loop. Every process has a callback that, when active, fires once per frame.

Install

NPM + Browserify (recommended)

First install Cycl in your project root.

$ npm install cycl

Then include in your module using require().

var cycl = require('cycl');

File include

Download the latest cycl.global.min.js from http://github.com/InventingWithMonster/cycl and include it in your HTML document with a script tag, ie:

<script src="/path/to/cycl.global.min.js"></script>

This will load Cycl to the global scope as window.cycl, accessible in any script executed subsequently.

Use

Example process

var process = cycl.newProcess(function (framestamp) {
    console.log('hello world! ' + framestamp);
});

process.start(); // Will output 'hello world' and the timestamp of the executing frame

To run a function with Cycl, we first have to create a new process. Active processes are fired once per frame.

Create a new process

The method newProcess takes the optional parameter scope, and a callback. If scope is provided, our callback executes in its context (this refers to scope). Otherwise the process itself is used as the context.

var process = cycl.newProcess(scope, callback);

Start a process

On creation, a process is not active. To start it, we simply call .start().

process.start(); // Our process runs

Stopping a process

We can stop this process with .stop().

process.stop(); // Our process stops

Run a process for a specific amount of time

Processes can be set to stop after a predefined period of time by passing start() a duration argument (in ms).

process.start(1000); // Our process runs for 1000ms

Run process every x seconds

Processes can be set to fire at regular intervals, like a framerate-locked setInterval().

process.every(100); // Our process runs once every 100ms

Change scope and callback

The scope and callback of a process can be changed with .setCallback() and setScope(). All these process methods can be chained.

process
    .setScope(newScope)
    .setCallback(newCallback)
    .start();

Kill a process (for garbage collection)

To remove a process from memory, you first need to run .kill(), which will delete it from cycl's internal tracking. Then delete any references to that object.

process.kill(); // Process is removed from Cycl, but still exists
delete process; // Now references to process are removed, garbage collection can take place.
1.1.0

10 years ago

1.0.0

11 years ago

0.2.5

11 years ago

0.2.4

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago