anothersequencer
Advanced tools
Comparing version 0.1.5 to 0.1.6
{ | ||
"name": "anothersequencer", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"description": "Simple script tree sequencer in javascript. Allows creating fairly complex trees of sync/async functions or requestAnimationFrame functions with optional delays, as well as subscribing to particular outputs in the tree at any time.", | ||
@@ -5,0 +5,0 @@ "main": "sequencer.js", |
@@ -46,2 +46,3 @@ ## Javascript function sequencing | ||
{ | ||
tag:'repeater' | ||
delay:1000, //ms delay for this call | ||
@@ -65,6 +66,6 @@ operation:(input)=>{ | ||
let sub = sequencer.subscribeToOperation('anotheroperation',onResult); //or .subscribe //adds a triggered function on result | ||
let sub = sequencer.subscribeToOperation('repeater',onResult); //or .subscribe //adds a triggered function on result | ||
//You could even, say, subscribe one tagged sequence to another tagged sequence. | ||
sequencer.unsubscribeFromOperation('anotheroperation',sub); //or .unsubscribe //leave sub blank to remove all triggers. | ||
sequencer.unsubscribeFromOperation('repeater',sub); //or .unsubscribe //leave sub blank to remove all triggers. | ||
@@ -86,5 +87,8 @@ ``` | ||
setting={ //object or function, functions cannot have more layers added | ||
//operation = (result) => {} //callback for the sequence, takes the previous result | ||
//operation:(result) => {} //callback for the sequence, takes the previous result | ||
//delay:undefined, //set to a millisecond value | ||
//async:undefined //set async:true or frame:true depending on if you want normal async or frame-timed async (which also won't run if you are out of the tab) | ||
//frame:undefined //setframe:true depending on if you want frame-timed async (which won't run if you are outside of the browser context) | ||
//tag:'xyz', //make subscribable outputs on this layer | ||
//repeat:3 //recursive:3 //repeater or recursive repeater. Recursion passes this layer's output back in rather than the parent layer | ||
tab) | ||
}, | ||
@@ -91,0 +95,0 @@ index //if you are appending to .next of an operation in a particular sequence layer you can use this. Leave blank to just add the setting to the specified layer instead |
@@ -37,3 +37,4 @@ //Simple script sequencer | ||
data:{}, | ||
setState:(updateObj)=>{ | ||
triggers:{}, | ||
setState(updateObj){ | ||
Object.assign(this.pushToState,updateObj); | ||
@@ -56,3 +57,3 @@ | ||
}, | ||
subscribeTrigger:(key,onchange=(res)=>{})=>{ | ||
subscribeTrigger(key,onchange=(res)=>{}){ | ||
if(key) { | ||
@@ -67,3 +68,3 @@ if(!this.triggers[key]) { | ||
}, | ||
unsubscribeTrigger:(key,sub)=>{ | ||
unsubscribeTrigger(key,sub){ | ||
let idx = undefined; | ||
@@ -94,9 +95,9 @@ let triggers = this.triggers[key] | ||
addSequence(name, sequence=[]) { | ||
add(name, sequence=[]) { | ||
this.sequences.set(name,sequence); | ||
} | ||
add=this.addSequence | ||
addSequence = this.add; | ||
async runSequence(name, input, runFromLayer=1) { | ||
async run(name, input, runFromLayer=1) { | ||
let sequence = this.sequences.get(name); | ||
@@ -118,3 +119,3 @@ if(sequence) { | ||
run = this.runSequence; | ||
runSequence = this.run; | ||
@@ -133,3 +134,3 @@ appendSequence( | ||
if(sequence) { | ||
if(!Array.isArray(sequence)) sequence = [sequence]; | ||
if(!Array.isArray(sequence)) sequence = [sequence]; //make the sequence layer an array if it isn't | ||
if(!index) sequence.push(setting); | ||
@@ -198,3 +199,3 @@ else { | ||
let result = await o.operation(prev); | ||
if(o.tag) this.state.setState(o.tag,result); | ||
if(o.tag) this.state.setState({[o.tag]:result}); | ||
if(typeof o.repeat === 'number') { //repeats a call with the first result | ||
@@ -291,3 +292,3 @@ let i = tick; | ||
//subscribes to a tagged operation | ||
subscribeToOperation(tag,callback=(result)=>{}) { | ||
subscribe(tag,callback=(result)=>{}) { | ||
if(tag) | ||
@@ -297,14 +298,15 @@ return this.state.subscribeTrigger(tag,callback); | ||
subscribe = this.subscribeToOperation; | ||
subscribeToOperation = this.subscribe; | ||
unsubscribeFromOperation(tag, sub) { | ||
unsubscribe(tag, sub) { | ||
if(tag) { | ||
this.state.unsubscribeTrigger(tag,sub); | ||
this.state.unsubscribeTrigger(tag,sub); | ||
} | ||
} | ||
unsubscribe = this.unsubscribeFromOperation; | ||
unsubscribeFromOperation = this.unsubscribe; | ||
} | ||
export default Sequencer |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
65125
7
349
110