npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fluid

v0.1.3

Published

Create fluent interfaces, inline, around any object, allowing simple chained async method calls.

Downloads

14,221

Readme

Fluid.js

Fluid.js is a simple fluent interface API for javascript and node.js. It is used to create fluent interfaces around existing vanilla objects, without all the boiler plate.

This is a useful extension to the excellent Async module.

NOTE: Fluid.js will only wrap methods which implement the following asynchronous signature:-

function(options, callback) -> callback(err, result)

Quick Examples

Example objects

For the sake of these examples imagine we have the following custom objects

var myFirstObj = {
	doSomething : function(options, callback) { 
		//do something
		callback(err, result);
	},
	doSomethingElse : function(options, callback) {
		//do something else
		callback(err, result);
	}
};

var mySecondObj = {
	doSomethingMore : function(options, callback) {
		//do something more
		callback(err, result);
	}
};

Setup

var fluid = require("fluid");

Expressive Example

fluid().series()		
	.with(myFirstObj)
		.doSomething({ /* args */ })
		.doSomethingElse({ /* args */ })
	.with(mySecondObj)
		.doSomethingMore({ /* args */ })
.go(function(err, results) {
	// results is now an array of return values passed to each method callback
});

Streamlined example

Note: series is the default flow control mode, so it can be ommitted

fluid(myFirstObj).doSomething({ /* args */ }).doSomethingElse({ /* args */ })
	.with(mySecondObj).doSomethingMore({ /* args */ })
.go(function(err, results) {
	// results is now an array of return values passed to each method callback
});

Multiple flow control types example

fluid()
	.series()		
		.with(myFirstObj)
			.doSomething({ /* args */ })
			.doSomethingElse({ /* args */ })
	.parallel()		
		.with(mySecondObj)
			.doSomethingMore({ /* args */ })
			.doSomethingMorer({ /* args */ })
			.doSomethingMorerer({ /* args */ })
	.go(function(err, results) {
		/*
			results is now an array (item for each queue) of arrays (item for each method return value)
		*/
	});

Install

To install with node package manager:

npm install fluid

Download

Releases are available for download from GitHub.

Appreciation

Thanks to caolan for his great module Async

Documentation

Fluid Context Methods


Creates a new fluent interface (fluid context), optionally wrapping an initial user specifed application context.

Note, if desired, the initial context can be left blank and applied later using the with command.

Arguments

  • context - An initial application context to wrap with fluent methods.
  • Returns a new fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).doSomething({ /* args */ })  
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

Fluid Context Methods


Switches the current application context to the one specified.

Note, The context can be switch as many times as required. Useful for cleanly working with multiple objects.

Arguments

  • context - An application context to wrap with fluent methods.
  • Returns the current fluid context.

Example

// assuming a objects exist called myObj and myObj2
var fluid = require("fluid");

fluid(myObj).doSomething({ /* args */ })
	.with(myObj2).doSomethingElse({ /* args */ }) 
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

Creates a new queue of method calls that will be executed in series. Multiple queues with different flow control types can be created, and will themselves be executed in series when the go command is called.

Note, This is the default execution mode when a new fluid context has been created.

Arguments

  • Returns the current fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).series()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }
	
	

Creates a new queue of method calls that will be executed in parallel. Multiple queues with different flow control types can be created, and will themselves be executed in series when the go command is called.

Note, see the Async module for more information on the difference between series and parallel flow controls.

Arguments

  • Returns the current fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).parallel()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

	

Executes all queued method calls against their registered application contexts, then invokes the specified callback when successfully completed, or any of the methods error.

Arguments

  • callback(err, res) - A callback which is called after all the methods have been called successfully, or an error has occurred. If no errors occurr res will be an array of return values passed to each method callback. If multiple queues have been executed it will be an array (item for each queue) of arrays (item for each method return value)

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).series()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	.parallel()
	.doSomethingMore({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { 
	if (err) { /* error */ } else {
		console.log(res[0][0]);
		console.log(res[0][1]);
		
		console.log(res[1][0]);
		/* .etc.etc... */
	}
}

The fluid context will wrap all properties of an application context that are functions.

NOTE: It is only possible to wrap functions that implement the following asynchronous signature:-

function(options, callback) -> callback(err, result)

Example

var myObj = {
	doSomething : function(options, callback) {
		callback(null, { prop1 : 1 });
	},
	doSomethingElse : function(options, callback) {
		callback({ message : "Error!" });
	},
	doSomethingMore : function(options, callback) {
		callback(null, { prop2 : 1 });
	}
};

var fluid = require("fluid");

fluid(myObj)
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	.doSomethingMore({ /* args */ })
.go(function(err, res) {
	/* finished with error, without executing doSomethingMore */

=======

Fluid.js

Fluid.js is a simple fluent interface API for javascript and node.js. It is used to create fluent interfaces around existing vanilla objects, without all the boiler plate.

This is a useful extension to the excellent Async module.

NOTE: Fluid.js will only wrap methods which implement the following asynchronous signature:-

function(options, callback) -> callback(err, result)

Quick Examples

Example objects

For the sake of these examples imagine we have the following custom objects

var myFirstObj = {
	doSomething : function(options, callback) { 
		//do something
		callback(err, result);
	},
	doSomethingElse : function(options, callback) {
		//do something else
		callback(err, result);
	}
};

var mySecondObj = {
	doSomethingMore : function(options, callback) {
		//do something more
		callback(err, result);
	}
};

Setup

var fluid = require("fluid");

Expressive Example

fluid().series()		
	.with(myFirstObj)
		.doSomething({ /* args */ })
		.doSomethingElse({ /* args */ })
	.with(mySecondObj)
		.doSomethingMore({ /* args */ })
.go(function(err, results) {
	// results is now an array of return values passed to each method callback
});

Streamlined example

Note: series is the default flow control mode, so it can be ommitted

fluid(myFirstObj).doSomething({ /* args */ }).doSomethingElse({ /* args */ })
	.with(mySecondObj).doSomethingMore({ /* args */ })
.go(function(err, results) {
	// results is now an array of return values passed to each method callback
});

Multiple flow control types example

fluid()
	.series()		
		.with(myFirstObj)
			.doSomething({ /* args */ })
			.doSomethingElse({ /* args */ })
	.parallel()		
		.with(mySecondObj)
			.doSomethingMore({ /* args */ })
			.doSomethingMorer({ /* args */ })
			.doSomethingMorerer({ /* args */ })
	.go(function(err, results) {
		/*
			results is now an array (item for each queue) of arrays (item for each method return value)
		*/
	});

Install

To install with node package manager:

npm install fluid

Download

Releases are available for download from GitHub.

Appreciation

Thanks to caolan for his great module Async

Documentation

Fluid Context Methods


Creates a new fluent interface (fluid context), optionally wrapping an initial user specifed application context.

Note, if desired, the initial context can be left blank and applied later using the with command.

Arguments

  • context - An initial application context to wrap with fluent methods.
  • Returns a new fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).doSomething({ /* args */ })  
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

Fluid Context Methods


Switches the current application context to the one specified.

Note, The context can be switch as many times as required. Useful for cleanly working with multiple objects.

Arguments

  • context - An application context to wrap with fluent methods.
  • Returns the current fluid context.

Example

// assuming a objects exist called myObj and myObj2
var fluid = require("fluid");

fluid(myObj).doSomething({ /* args */ })
	.with(myObj2).doSomethingElse({ /* args */ }) 
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

Creates a new queue of method calls that will be executed in series. Multiple queues with different flow control types can be created, and will themselves be executed in series when the go command is called.

Note, This is the default execution mode when a new fluid context has been created.

Arguments

  • Returns the current fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).series()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }
	
	

Creates a new queue of method calls that will be executed in parallel. Multiple queues with different flow control types can be created, and will themselves be executed in series when the go command is called.

Note, see the Async module for more information on the difference between series and parallel flow controls.

Arguments

  • Returns the current fluid context.

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).parallel()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { /* finished */ }

	

Executes all queued method calls against their registered application contexts, then invokes the specified callback when successfully completed, or any of the methods error.

Arguments

  • callback(err, res) - A callback which is called after all the methods have been called successfully, or an error has occurred. If no errors occurr res will be an array of return values passed to each method callback. If multiple queues have been executed it will be an array (item for each queue) of arrays (item for each method return value)

Example

// assuming an object exists called myObj
var fluid = require("fluid");

fluid(myObj).series()
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	.parallel()
	.doSomethingMore({ /* args */ })
	/* .etc.etc... */
.go(function(err, res) { 
	if (err) { /* error */ } else {
		console.log(res[0][0]);
		console.log(res[0][1]);
		
		console.log(res[1][0]);
		/* .etc.etc... */
	}
}

The fluid context will wrap all properties of an application context that are functions.

NOTE: It is only possible to wrap functions that implement the following asynchronous signature:-

function(options, callback) -> callback(err, result)

Example

var myObj = {
	doSomething : function(options, callback) {
		callback(null, { prop1 : 1 });
	},
	doSomethingElse : function(options, callback) {
		callback({ message : "Error!" });
	},
	doSomethingMore : function(options, callback) {
		callback(null, { prop2 : 1 });
	}
};

var fluid = require("fluid");

fluid(myObj)
	.doSomething({ /* args */ })
	.doSomethingElse({ /* args */ })
	.doSomethingMore({ /* args */ })
.go(function(err, res) {
	/* finished with error, without executing doSomethingMore */

Fixed package and readme }