Socket
Socket
Sign inDemoInstall

zig

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zig - npm Package Compare versions

Comparing version 0.0.2 to 0.1.0

build.sh

22

package.json
{
"name": "zig",
"version": "0.0.2",
"version": "0.1.0",
"description": "Simple, but naughty, control flow for Node.js.",
"main": "zig.js",
"scripts": {
"test": "./node_modules/.bin/mocha test/*.test.js"
"test": "./test.sh",
"build": "./build.sh"
},
"repository": {
"type": "git",
"url": "git://github.com/rjrodger/zig.git"
},
"keywords": [
"zig",
"chain",
"chaining",
"step",
"wait",
"task"
],
"author": "Richard Rodger (http://richardrodger.com/)",
"license": "MIT",
"devDependencies": {
"mocha": "^1.21.5"
},
"dependencies": {
"underscore": "^1.7.0"
"lodash": "~2.4.1"
}
}

@@ -7,21 +7,28 @@ Zig - Simple, but naughty, control flow for Node.js

A special case solution for callback hell that focuses on developer
ease-of-use. Executes your functions in series or parallel, tracks errors and
results, and provides conditionals.
ease-of-use. Executes your functions in series or parallel, tracks
errors and results, **and provides conditionals**.
Allows you to move blocks of code around to change the order of
execution.
Current Version: 0.1.0
Tested on: Node 0.10.35
[![Build Status](https://travis-ci.org/rjrodger/zig.png?branch=master)](https://travis-ci.org/rjrodger/zig)
[![NPM](https://nodei.co/npm/zig.png)](https://nodei.co/npm/zig/)
[![NPM](https://nodei.co/npm-dl/zig.png)](https://nodei.co/npm-dl/zig/)
[Annotated Source](http://rjrodger.github.io/zig/doc/zig.html)
If you're using this plugin module, feel free to contact me on twitter if you
# Support
If you're using this module, feel free to contact me on twitter if you
have any questions! :) [@rjrodger](http://twitter.com/rjrodger)
Current Version: 0.0.2
[![Gitter chat](https://badges.gitter.im/rjrodger/zig.png)](https://gitter.im/rjrodger/zig)
Tested on: Node 0.10.31
# Install
### Install
```sh

@@ -34,64 +41,114 @@ npm install zig

Here's the classic Mongo example. Look ma, no callbacks! Nice and
linear down the page.
Some callbacks:
```js
var zig = require('..')
function color(val,callback) {
callback(null,{color:val})
}
var MongoClient = require('mongodb').MongoClient
var format = require('util').format;
function quality(val,callback) {
callback(null,{quality:val})
}
var db,collection
function sound(val,callback) {
callback(null,{sound:val})
}
zig({trace:false})
function texture(val,callback) {
callback(null,{texture:val})
}
```
Nice and linear down the page.
```js
var zig = require('..')
var result = {}
zig()
.start()
.wait(function(data,done){
MongoClient.connect('mongodb://127.0.0.1:27017/test', done)
color('red',done)
})
.step(function(data){
db = data
return collection = db.collection('test_insert')
console.log('color:'+data.color)
return result.color = data.color
})
.wait(function(data,done){
collection.insert({a:2},done)
quality('high',done)
})
.step(function(data){
console.log('quality:'+data.quality)
return result.quality = data.quality
})
.if( Math.random() < 0.5 )
.wait(function(data,done){
collection.count(done)
sound('violin',done)
})
.step(function(count){
console.log(format("count = %s", count));
return true;
.step(function(data){
console.log('sound:'+data.sound)
return result.sound = data.sound
})
.endif()
.wait(function(data,done){
collection.find().toArray(done)
texture('rough',done)
})
.end(function(err,docs){
if( err ) return console.log(err);
console.dir(docs)
db.close()
.step(function(data){
console.log('texture:'+data.texture)
return result.texture = data.texture
})
.end(function(err){
if( err ) return console.log(err)
console.log(result)
})
```
And the original, callback hell:
Versus callback hell:
```js
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
var result = {}
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
if(err) throw err;
color('red', function(err,data){
if( err ) return console.log(err)
var collection = db.collection('test_insert');
collection.insert({a:2}, function(err, docs) {
result.color = data.color
console.log('color:'+data.color)
collection.count(function(err, count) {
console.log(format("count = %s", count));
});
quality('high', function(err,data){
if( err ) return console.log(err)
collection.find().toArray(function(err, results) {
console.dir(results);
db.close();
});
});
result.quality = data.quality
console.log('quality:'+data.quality)
if( Math.random() < 0.5 ) {
sound('violin',function(err,data){
if( err ) return console.log(err)
result.sound = data.sound
console.log('sound:'+data.sound)
do_texture()
})
}
else do_texture()
function do_texture() {
texture('rough', function(err,data){
if( err ) return console.log(err)
result.texture = data.texture
console.log('texture:'+data.texture)
console.log(result)
})
}
})
})
```

@@ -109,2 +166,3 @@

* 0.1.0: normalize test, build, and readme
* 0.0.2: steps can exit

@@ -111,0 +169,0 @@ * 0.0.1: first working version

@@ -1,2 +0,4 @@

//"use strict";
/* Copyright (c) 2014-2015 Richard Rodger, MIT License */
"use strict";
/* jshint node:true, asi:true, eqnull:true */

@@ -6,3 +8,3 @@

var _ = require('underscore')
var _ = require('lodash')

@@ -75,3 +77,3 @@

trace(step.type,step.fn.nm,data)
if( 0 == collect ) return wait_fn();
if( 0 === collect ) return wait_fn();
check_collect()

@@ -92,3 +94,3 @@ }

ifdepth = ifdepth < 0 ? 0 : ifdepth;
active = 0 == ifdepth;
active = 0 === ifdepth;

@@ -138,2 +140,3 @@ trace(step.type,step.fn.nm,active,ifdepth+1)

else if( _.isString(cond) ) {
/* jshint evil:true */
bool = !!eval(cond)

@@ -140,0 +143,0 @@ }

Sorry, the diff of this file is not supported yet

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