lego ·
Legofy is a JavaScript library for building modular extendable functions.
- Declarative: Legofy let you use your modules in a very declarative way, it makes your code more predictable, simpler to understand, and easier to debug.
- Focused: It handles both Sync and Async modules, so that you only focus on the steps and how to connect different modules.
- Promise-like syntax You'll notice that we used an Promise-like syntax, so that writing it feels like home. Learn how to use legofy in your own project.
Examples
We have several examples on the website. Here are some to get you started:
var lego = // 9
var lego = //10
var lego = //20
Those examples show how you can declare legos and start using them in a promise like syntax, they also show how you can attach a catch statement after some step so that you can handle the error and resume the rest of your steps
Legos will act sync when no async code found ie (Functions that returns a promise etc...)
var fun =
var fun =
var fun =
Notice how Legos resolve into promises when async blocks found
var legoPiece = var legoPiecePlus1 = legoPiece var legoPiecePlus2 = legoPiece //6 //7 //30
var legoPiece = var legoPiecePlus = legoPiece var legoPiecePlusPlus = legoPiecePlus //6 //7 //8
var legoPiece = var legoPiecePlus = legoPiece var legoPiecePlusPlus = legoPiecePlus
var legoPiece = var legoPiecePlus1 = legoPiece var legoPiecePlus2 = legoPiece
var legoPiece = var legoPiecePlus1 = legoPiece var legoPiecePlus2 = legoPiece //"lol1" //"lol2"
var legoPiece = var legoPiecePlus1 = legoPiece var legoPiecePlus2 = legoPiece try catch e emessage //"lol" //1 //2
var legoPiece = var legoPiecePlus1 = legoPiece var legoPiecePlus2 = legoPiece try catch e emessage //"lol" //2 //undefined
Notice how legos can be easily extended and exchanged
var legoPiece = var legoPiecePlus = legoPiece //no async steps found so it will execute sync //6 //an async step found so it will return a promise
var legoPiece = var legoPiecePlus = legoPiece var legoPiecePlusPlus = legoPiecePlus //no async steps found so it will execute sync //6 //an async step found so it will return a promise //an async step found so it will return a promise
Notice how legos executes sync till an async step interrupts
var lego1 = var lego2 = var legoCon1 = lego1var legoCon2 = lego2 //4 //3 //5 //6
var lego1 = var lego2 = var legoCon1 = lego1var legoCon2 = lego2 //4
var lego1 = var lego2 = var legoCon1 = lego1var legoCon2 = lego2 try catch e emessage; //"lol" try catch e emessage; //"lol" ; //6; //10
var lego1 = var lego2 = var legoCon1 = lego1var legoCon2 = lego2 ; //6
- legofy offers you a new pattern of writing modular reusable code that handles both sync and async callbacks to let you focus on building your logic and declare your steps.
- Legos can be easily extended and you can literally build your app out of small little legos
- Legos make your code very declarative beacause each legoPiece kind of represents a step, so it's alot easier for anyone to reason about your logic
License
legofy is MIT licensed.