Socket
Socket
Sign inDemoInstall

react

Package Overview
Dependencies
3
Maintainers
1
Versions
1841
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.2 to 0.2.0

examples/default1.js

1

lib/core.js

@@ -48,2 +48,3 @@ 'use strict';

var ast = {
name: undefined,
inParams: [],

@@ -50,0 +51,0 @@ tasks: [],

@@ -6,2 +6,3 @@ 'use strict';

function splitTrimFilterArgs(commaSepArgs) { //parse 'one, two' into ['one', 'two']
if (!commaSepArgs) return [];
return commaSepArgs.split(',') //split on commas

@@ -8,0 +9,0 @@ .map(function (s) { return s.trim(); }) //trim

2

package.json
{
"name": "react",
"description": "React is a javascript module to make it easier to work with asynchronous code, by reducing boilerplate code and improving error and exception handling while allowing variable and task dependencies when defining flow.",
"version": "0.1.2",
"version": "0.2.0",
"author": "Jeff Barczewski <jeff.barczewski@gmail.com>",

@@ -6,0 +6,0 @@ "repository": { "type": "git", "url": "http://github.com/jeffbski/react.git" },

@@ -5,9 +5,9 @@ 'use strict';

module.exports = core;
module.exports.options = core.options;
module.exports.events = core.events; // top level emitter
module.exports = require('./lib/dsl.js'); // core + default dsl
module.exports.options = core.options; // global react options
module.exports.events = core.events; // global react event emitter
// interfaces
// additional interfaces
module.exports.fstrDefine = require('./lib/fstr.js');
module.exports.pcodeDefine = require('./lib/pcode.js');
module.exports.chainDefine = require('./lib/chain.js');

@@ -28,9 +28,9 @@ # React.js

- Minimize boilerplate code needed for working with asynchronous functions
- Minimize the need to customize your code simply to use async flow control. The use of a flow control module ideally should not affect the way you write your code, it should only help take over some of the burden.
- Improved error and exception handling
- Provide useful stack traces and context information for easier debugging
- Minimize boilerplate code needed for working with asynchronous functions
- Make code more readable and easier to understand which should translate to less defects
- Provide the right level of abstraction to make it easier to refactor code, without being too magical
- Allow the mixing of pure functions, method calls, and callback style functions in the flow
- Minimize the need to customize your code simply to use async flow control. The use of a flow control module ideally should not affect the way you write your code, it should only help take over some of the burden.

@@ -65,5 +65,5 @@ ## Supports

- Parse and validate ad module load time
- Parse and validate DSL rules at module load time
- Validate the flow AST at module load time - determine if dependencies can all be met as defined
- Execute the flow AST by calling the function with params
- Execute the flow AST by calling the function with arguments

@@ -80,4 +80,4 @@ ## Installing

1. [Direct AST](#directAST)
2. [Using Function Str DSL](#fstr)
1. [Default DSL](#defaultDSL)
2. [Direct AST](#directAST)
3. [Using pseudocode DSL](#pcode)

@@ -91,2 +91,40 @@ 4. [Using jquery-like chaining DSL](#chain)

<a name="defaultDSL"/>
### Example using default DSL
```javascript
// in your foo module
var react = require('react');
// some normal async and sync functions
function loadUser(uid, cb){ }
function loadFile(filename, cb){ }
function markdown(filedata) { }
function writeOutput(html, user, cb){ }
function loadEmailTemplate(cb) { }
function customizeEmail(user, emailHtml, cb) { }
function deliverEmail(custEmailHtml, cb) { }
// define fn, glue together with react, it will parallelize
// starts with name and in/out params, then the tasks
var loadAndSend = react('loadAndSend', 'uid, filename, cb -> err, user',
loadUser, 'uid, cb -> err, user',
loadFile, 'filename, cb -> err, filemd',
markdown, 'filemd -> html', // no cb, implies sync fn
writeOutput, 'html, user, cb -> err, htmlBytesWritten',
loadEmailTemplate, 'cb -> err, emailmd',
markdown, 'emailmd -> emailHtml', // no cb, implies sync fn
customizeEmail, 'user, emailHtml, cb -> err, custEHtml',
deliverEmail, 'custEHtml, cb -> err, custBytesWritten'
);
exports.loadAndSend = loadAndSend; // is a normal fn created by react
// in a different module far far away, use this as any other node function
var foo = require('foo');
foo.loadAndSend(100, 'bar.md', function (err, user) {
// tasks were parallelized based on their depedencies
}
```
<a name="directAST"/>

@@ -211,2 +249,3 @@ ### Example directly using AST

- 2012-01-10 - Create default DSL for react()
- 2011-12-21 - Refactor from ground up with tests, changes to the interfaces

@@ -222,2 +261,3 @@ - 2011-10-26 - React is in active development and interface may change frequently in these early stages. Current code is functional but does not perform validation yet. Additional interfaces are planned to make it easy to define flows in a variety of ways. Documentation and examples forthcoming.

ok core.test.js ................... 98/98
ok dsl.test.js .................... 58/58
ok event-manager.test.js .......... 13/13

@@ -228,3 +268,3 @@ ok exec-options.test.js ............. 3/3

ok input-parser.test.js ........... 15/15
ok module-use.test.js ............. 55/55
ok module-use.test.js ............. 64/64
ok pcode.test.js .................. 65/65

@@ -237,3 +277,3 @@ ok ret-task.test.js ............... 31/31

ok vcon.test.js ................... 42/42
total ........................... 545/545
total ........................... 613/613

@@ -240,0 +280,0 @@ ok

@@ -12,9 +12,12 @@ 'use strict';

react.options.an_option = 'something';
var loadAndSave = react.fstrDefine('one, two, cb -> err, result1, result2',
foo, 'one -> err, cat',
bar, 'two, cat -> err, dog',
baz, 'dog -> err, result1',
bum, 'dog -> err, result2');
// define function
var loadAndSave = react('myName', 'one, two, cb -> err, result1, result2',
foo, 'one, cb -> err, cat',
bar, 'two, cat, cb -> err, dog',
baz, 'dog, cb -> err, result1',
bum, 'dog, cb -> err, result2');
// OR using AST
var loadAndSave = react();

@@ -30,7 +33,7 @@ loadAndSave.setAndValidateAST({

loadAndSave(1,2,cb);
loadAndSave(1,2,cb); // execute like any other function
*/
test('module exports an function object with properties', function (t) {
t.type(react, 'function', 'is a core constructor function');
t.type(react, 'function', 'is a core constructor and default dsl function');
t.type(react.options, 'object', 'has property for global react options');

@@ -52,14 +55,6 @@ t.type(react.fstrDefine, 'function', 'has fn property for using fstr dsl');

t.deepEqual(r.ast.tasks, [], 'ast.tasks() should return empty array');
t.deepEqual(r.ast.outTask, {}, 'should return empty object');
t.deepEqual(r.ast.outTask, { a: [], type: 'finalcb' });
t.end();
});
test('deprecated react API should throw to help debugging', function (t) {
function badUse() {
var r = react('filename, uid, outDirname, cb'); //this should throw
}
t.throws(badUse, new Error('react() takes no args, check API'));
t.end();
});
test('setAndValidateAST sets the ast and validates returning errors', function (t) {

@@ -84,3 +79,54 @@ var r = react();

test('use react() default DSL from module', function (t) {
t.plan(3);
function multiply(a, b, cb) { cb(null, a * b); }
function add(a, b, cb) { cb(null, a + b); }
var fn = react('multiplyAdd', 'a, b, cb -> err, m, s',
multiply, 'a, b, cb -> err, m',
add, 'm, a, cb -> err, s'
);
fn(2, 3, function (err, m, s) {
t.deepEqual(err, null, 'should not be any error');
t.equal(m, 6);
t.equal(s, 8);
t.end();
});
});
test('use react.selectFirst() default DSL with events', function (t) {
t.plan(7);
function noSuccess(a, b, cb) {
setTimeout(function () { cb(null); }, 100); // returns undefined result
}
function noSuccessNull(a, b, cb) { cb(null, null); } // returns null result
function add(a, b, cb) { cb(null, a + b); }
var events = [];
function accumEvents(task) {
events.push(task);
}
var fn = react.selectFirst('mySelectFirst', 'a, b, cb -> err, c',
noSuccess, 'a, b, cb -> err, c',
noSuccessNull, 'a, b, cb -> err, c',
add, 'a, b, cb -> err, c',
noSuccess, 'a, b, cb -> err, c'
);
fn.events.on('task.complete', accumEvents);
fn(2, 3, function (err, c) {
t.deepEqual(err, null, 'should not be any error');
t.equal(c, 5);
t.equal(events.length, 3, 'should have seen two task compl events');
t.equal(events[0].name, 'noSuccess', 'name matches');
t.equal(events[1].name, 'noSuccessNull', 'name matches');
t.equal(events[2].name, 'add', 'name matches');
t.deepEqual(events[2].results, [5], 'results match');
t.end();
});
});
test('use pcodeDefine from module', function (t) {

@@ -87,0 +133,0 @@ t.plan(3);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc