Comparing version 0.0.2 to 0.0.3
@@ -162,2 +162,3 @@ "use strict"; | ||
flow.children.value.push(instance); | ||
dispatchInternalEvent(flow, "create", instance); | ||
return instance; | ||
@@ -344,6 +345,6 @@ }; | ||
}; | ||
behaviours.log = function (flow) { | ||
behaviours.loggable = function (flow) { | ||
flow.toString = function () { | ||
return "{ Object Flow }"; | ||
return "{ Object Flow, name:%name }".replace("%name", flow.name()); | ||
}; | ||
@@ -390,3 +391,3 @@ }; | ||
}, | ||
behaviours: [behaviours.identify, behaviours.stateful, behaviours.connect, behaviours.create, behaviours.emit, behaviours.listen, behaviours.cancellable, behaviours.log], | ||
behaviours: [behaviours.identify, behaviours.stateful, behaviours.connect, behaviours.create, behaviours.emit, behaviours.listen, behaviours.cancellable, behaviours.loggable, behaviours.loggable], | ||
direction: DIRECTION.DEFAULT | ||
@@ -444,2 +445,6 @@ }; | ||
function log(flow, name, newData, oldData) { | ||
instance.logger && instance.logger(flow, name, newData, oldData); | ||
} | ||
function dispatchInternalEvent(flow, name, newData, oldData) { | ||
@@ -460,3 +465,6 @@ var e = create(DEFAULTS, "flow." + name); | ||
e.emit(); | ||
log(flow, name, newData, oldData); | ||
} | ||
var instance = create(DEFAULTS, "flow"); | ||
@@ -463,0 +471,0 @@ |
{ | ||
"name": "nflow", | ||
"version": "0.0.2", | ||
"description": "hierarchical event dispatcher", | ||
"version": "0.0.3", | ||
"description": "event/data/control flow", | ||
"main": "dist/flow.js", | ||
@@ -10,3 +10,3 @@ "scripts": { | ||
"keywords": [ | ||
"information", | ||
"event", | ||
"data", | ||
@@ -13,0 +13,0 @@ "control", |
# nFlow | ||
# nFlow [![Build Status](https://travis-ci.org/mere/nflow.svg?branch=master)](https://travis-ci.org/mere/nflow) | ||
Hierarchical event dispatcher | ||
[![NPM](https://nodei.co/npm/nflow.png?compact=true)](https://nodei.co/npm/nflow/) | ||
### Work in progress | ||
@@ -6,0 +8,0 @@ |
@@ -7,2 +7,3 @@ behaviours.create = (flow, defaults)=>{ | ||
flow.children.value.push(instance) | ||
dispatchInternalEvent(flow, 'create', instance) | ||
return instance | ||
@@ -9,0 +10,0 @@ } |
@@ -30,3 +30,4 @@ /** | ||
behaviours.cancellable, | ||
behaviours.log | ||
behaviours.loggable, | ||
behaviours.loggable | ||
], | ||
@@ -33,0 +34,0 @@ direction: DIRECTION.DEFAULT |
@@ -45,2 +45,7 @@ /** | ||
function log(flow, name, newData, oldData){ | ||
instance.logger | ||
&& instance.logger(flow, name, newData, oldData) | ||
} | ||
function dispatchInternalEvent(flow, name, newData, oldData){ | ||
@@ -62,5 +67,10 @@ var e= create(DEFAULTS, "flow."+name) | ||
log(flow, name, newData, oldData) | ||
} | ||
} | ||
@@ -116,6 +116,49 @@ | ||
describe('create() API', function(){ | ||
it('should dispatch flow.create internal event', function(done){ | ||
sut | ||
.on("flow.create", (f)=>{ | ||
expect(f.name()).to.equal("test") | ||
done() | ||
}) | ||
.create('test') | ||
}) | ||
it('should dispatch flow.children.create internal event', function(done){ | ||
sut | ||
.on("flow.children.create", (f, flowCreated)=>{ | ||
expect(f.name()).to.equal("sut") | ||
expect(flowCreated.name()).to.equal("test") | ||
done() | ||
}) | ||
.create('test') | ||
}) | ||
it('should dispatch flow.children.data internal event', function(done){ | ||
var payload = {} | ||
var listener = function(f, newData, oldData){ | ||
expect(newData).to.equal(data2) | ||
expect(oldData).to.equal(data1) | ||
done() | ||
} | ||
var data1 = 1 | ||
var data2 = 2 | ||
sut | ||
.on('flow.children.data', listener) | ||
.create('test', data1) | ||
.data(data2) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77057
28
1514
76