SchQ
SchQ is an event-scheduling pipeline that I’ve created to schedule d3 animations. It can also be used for preforming the same operation in any other sequence where controlling the order of events needs to be automatically canceled when the state of the application has changed.
Example:
// initialize SchQ
let config = {
// schQ intentionally discards data when application state changes
// set lost data to the number of history items if you wish to track
// that discarded data.
lostData : 0,
// a function to make a consistent array
preprocess: (array) => {...do something},
// what will happen last after sequence is done
doLast: [[()=>console.log('done')]],
// count items out for process
checkout: (eachObject) => eachObject.opperation.length
};
let schQ = new SchQ(config);
// load data and a key
schQ.loader([[func,func],[func]], 'data');
// run
let subscriber = schQ.run();
// subcribe
subscriber
.subscribe(packet => {
let {message, next, emitter} = packet;
// key is 'data'
// previous is any data returned from events if not the first event
let {key, previous} = message;
next.forEach(operationThen => {
operationThen( previous, emitter.emit({key}) );
});
});
Constructor Summary
Public Constructor | ||
public |
constructor(config: Object) |
Method Summary
Public Methods | ||
public |
SchQ.emitter: give access to the emitter to hook an event from another API |
|
public |
SchQ.loader: pushes data to the pipeline and gives the event listener a key to listen on. |
|
public |
run(): Observable SchQ.run: creates the Observable scheduler sequence |
Public Constructors
public constructor(config: Object) source
Params:
Name | Type | Attribute | Description |
config | Object |
|
Object of arguments |
config.checkout | Function |
|
how schQ know how many operations are outstanding before pushing the next event |
config.doLast | Function |
|
what is performed when all process are finished. i.e. default is () => {} |
config.lostData | Number |
|
Set the number of lost data items to track for tests or have another use cases |
config.preprocess | Function |
|
create a interable i.e. default is an Array of Arrays of Functions |
Public Methods
public emitter(): Emitter source
SchQ.emitter: give access to the emitter to hook an event from another API
public loader(next: Array, key: String) source
SchQ.loader: pushes data to the pipeline and gives the event listener a key to listen on.
Params:
Name | Type | Attribute | Description |
next | Array | an Array of Arrays that pushes each nested array to the subscribe of the like a queue. |
|
key | String | This key is used to subscribe to an event before pushed down the pipeline. Once you subscribe to the pipeline this key will available via {}.message to emit on. |
public run(): Observable source
SchQ.run: creates the Observable scheduler sequence
Return:
Observable | Observable on which to subscribe |
Return Properties:
Name | Type | Attribute | Description |
message | Object | object of event key and previous events |
|
message.key | Object | key emitter is listening if on |
|
message.previous | Array | undefined | an array of previous events if not the first event, else undefined |
|
next | Object | the operation to perform |
|
emitter | Emitter | for emit |