Giter Club home page Giter Club logo

setten's Introduction

setten

Dojo Toolkit style utilities and wrappers for Node.

This package is designed to provide Dojo-style AMD modules to make working with NodeJS more the "Dojo way".

License

This code is licensed under the "New" BSD License.

Installation

Via cpm:

$ cpm install setten

Via volo:

$ volo add kitsonk/setten

Tests

The unit tests included with the package leverage the Dojo Objective Harness (D.O.H.). In order to leverage D.O.H. it is assumed that the dojo package and the util directory of Dojo which contains the doh package are installed as siblings of the setten package, for example:

lib/dojo
lib/setten
lib/util/doh

This can be changed by modifying the setten/tests/index.js package map.

The execute the tests, execute the following command from the /setten directory:

$ node tests

Modules

setten/dfs

This is a wrapper for the NodeJS fs module, that takes the asynchronous callback calls and converts them into a dojo/promise Promise based return.

For example, you might have written code like this in "plain" NodeJS:

var fs = require("fs");

fs.readFile("/etc/passwd", function(err, data){
	if(err) throw err;
	console.log(data);
});

This could now be rewritten as:

require(["setten/dfs"], function(dfs){
	dfs.readFile("/etc/passwd").then(function(data){
		console.log(data);
	}, function(err){
		throw err;
	});
});

setten/dfs-extra

This is a wrapper for the fs-extra module. This takes the extra functions provides by this library and provides a dojo/promise based return.

setten/util

This is a utility library used internally within the package. It provides a convenience function that converts callback functions into a dojo/promise Promise return. It would work like this:

require(["setten/util"], function(util){
	var fn = function(data, callback){
		// do something async
		callback(err, info);
	}

	var pfn = util.asDeferred(fn, this, false);

	pfn("something").then(function(info){
		// async return
	}, function(err){
		// handle error
	});
});

The arguments for asDeferred() are:

Argument Type Description
fn Function The function whos return should be converted to a Promise.
self Object? The scope to be used in conjunction with the function. Defaults to this.
noError Boolean? true if the callback does not include an error argument. Defaults to false.

Because promises can only be fulfilled with a single value, if the callback is called with more than one argument (minus the error argument) then the promise is fulfilled with the supplied arguments as an array, otherwise it just fufills with the single argument it was passed.

setten's People

Contributors

kitsonk avatar

Stargazers

Andrew Smagin avatar Rodrigo González Castillo avatar Christophe Beveraggi avatar

Watchers

James Cloos avatar  avatar Hung avatar  avatar

setten's Issues

fs create stream problems

Hello,
I really appreciate your work but I've just found a small bug.
fs.createReadStream
fs.createWriteStream
should not be threated as Deferred:
a fix could be to change dfs.js#11
in
if (typeof fs[f] === 'function' && !/(^create|^_|Sync$)/.test(f)) { // It is something we want to convert

maybe there are problems with watch things too

Cheers,
kiuma

Change name

I really love your work with node + dojo.

Unfortunately, substack has a project on NPM called dnode and this might get confusing.

https://github.com/substack/dnode

Not sure what would be a better name, but I would love to see these wrappers on NPM at some point.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.