Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

anothersequencer

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

anothersequencer

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.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
2
Weekly downloads
 
Created
Source

Javascript function sequencing

Quick and dirty script sequencer. Create function trees, add async/requestAnimationFrame or delays, and subscribe to tagged outputs in the trees.

npm i anothersequencer

Usage:

import {Sequencer} from 'anothersequencer' //or copy the html
//import {Sequencer} from './Sequencer.js'
//in HTML: <script type='module' src='./Sequencer.js></script>
//or for lazy: 
//document.head.insertAdjacentHTML(`<script type='module' src='./Sequencer.js></script>`)

let sequencer = new Sequencer();

//simple sequences will pass the previous result along in the order of the array
let sequence1 = [ 
    (input)=>{console.log('a',input); return 1;},
    (input)=>{console.log('a',input); return 2;}, //should log 1
    async (input) => {console.log('a',input); return 3;} //should log 2
];

sequencer.addSequence('a',sequence1);

sequencer.runSequence('a', 0); //these run async

//complex
let sequence2 = { //create a sequence object or array, can mix and match for each layer as well
    operation:(input)=>{
        console.log('b',input);
        return 5;
    },
    next:[ //Calls here receive the parent result.
        {
            operation:(input)=>{
                console.log('b',input);
                return 6;
            },
            frame:true // can execute with requestAnimationFrame
            next:async (input)=>{console.log('b',input);} //can end with a function
        },
        {
            delay:1000, //ms delay for this call
            operation:(input)=>{
                console.log('b',input);
                return 7;
            },
            next:'a' //or can end with another sequence tag
        }
    ]
}

sequencer.addSequence('b',sequence2);

sequencer.runSequence('b',4);

let sub = sequencer.subscribeToOperation('anotheroperation',onResult); //adds a triggered function on result
//You could even, say, subscribe one tagged sequence to another tagged sequence.

//sequencer.unsubscribeFromOperation('anotheroperation',sub); //leave sub blank to remove all triggers. 

Other functions less obvious to use:

sequencer.getSequence(
    name,
    layer //optional
);
sequencer.appendSequence(
     name, //name of sequence
    layer, //layer 2 is the second layer, etc. leave blank to append on first layer
    setting={ //object or function, functions cannot have more layers added
    //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)
    }, 
    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
)
sequencer.removeSequence(
    name,
    layer, //optional
    index //optional
);
//this is used recursively by runSequence otherwise to iterate a layer
sequencer.runSequenceLayer(
    layer,
    previousResult
)

Keywords

FAQs

Package last updated on 27 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc