Comparing version 0.0.3 to 0.0.4
@@ -59,2 +59,3 @@ "use strict"; | ||
var filter = matcher; | ||
if (matcher == null) return []; | ||
if (typeof matcher == "string") filter = function (f) { | ||
@@ -70,2 +71,5 @@ return f.name() == matcher; | ||
flow.get = flow.children.find; | ||
flow.getAll = flow.children.find; | ||
/** | ||
@@ -161,3 +165,8 @@ * return all children recursively | ||
var instance = create(flow.create.defaults, name, data); | ||
var instance = flow.get(name); | ||
if (instance) { | ||
instance.data.apply(instance, data); | ||
return instance; | ||
} | ||
instance = create(flow.create.defaults, name, data); | ||
instance.parent.value = flow; | ||
@@ -209,3 +218,5 @@ flow.children.value.push(instance); | ||
detach(flow); | ||
log(flow, "emit", flow); | ||
flow.emit.route(flow); | ||
log(flow, "emitted", flow); | ||
return flow; | ||
@@ -219,3 +230,5 @@ } | ||
detach(flow); | ||
log(name, "emit", name); | ||
flow.emit.route(name); | ||
log(name, "emitted", name); | ||
return flow; | ||
@@ -228,3 +241,5 @@ } | ||
detach(event); | ||
log(event, "emit", event); | ||
flow.emit.route(event); | ||
log(event, "emitted", event); | ||
return event; | ||
@@ -307,5 +322,8 @@ }; | ||
assert(typeof name != "string", ERRORS.invalidName, name); | ||
return (flow.name.value = name, flow); | ||
var previousName = flow.name.value; | ||
flow.name.value = name; | ||
dispatchInternalEvent(flow, "name", name, previousName); | ||
return flow; | ||
}; | ||
flow.name(name || flow.guid()); | ||
flow.name.value = name || flow.guid(); | ||
flow.name.isFlow = true; | ||
@@ -450,3 +468,3 @@ flow.name.isInternal = false; | ||
function log(flow, name, newData, oldData) { | ||
instance.logger && instance.logger(flow, name, newData, oldData); | ||
instance.logger && !isInternal(flow) && instance.logger(flow, name, newData, oldData); | ||
} | ||
@@ -453,0 +471,0 @@ |
{ | ||
"name": "nflow", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "event/data/control flow", | ||
@@ -5,0 +5,0 @@ "main": "dist/flow.js", |
@@ -17,2 +17,3 @@ behaviours.connect = (flow)=>{ | ||
var filter = matcher; | ||
if (matcher==null) return [] | ||
if (typeof(matcher)=="string") filter = f=>f.name()==matcher | ||
@@ -27,2 +28,5 @@ else if (isFlow(matcher)) filter = f=>f==matcher | ||
flow.get = flow.children.find | ||
flow.getAll = flow.children.find | ||
/** | ||
@@ -29,0 +33,0 @@ * return all children recursively |
behaviours.create = (flow, defaults)=>{ | ||
flow.create = (name, ...data) => { | ||
var instance = create(flow.create.defaults, name, data) | ||
var instance = flow.get(name) | ||
if (instance){ | ||
instance.data(...data) | ||
return instance | ||
} | ||
instance = create(flow.create.defaults, name, data) | ||
instance.parent.value = flow | ||
@@ -6,0 +12,0 @@ flow.children.value.push(instance) |
@@ -24,3 +24,5 @@ behaviours.emit = (flow)=>{ | ||
detach(flow) | ||
log(flow, 'emit', flow) | ||
flow.emit.route(flow) | ||
log(flow, 'emitted', flow) | ||
return flow | ||
@@ -34,3 +36,5 @@ } | ||
detach(flow) | ||
log(name, 'emit', name) | ||
flow.emit.route(name) | ||
log(name, 'emitted', name) | ||
return flow | ||
@@ -44,3 +48,5 @@ } | ||
detach(event) | ||
log(event, 'emit', event) | ||
flow.emit.route(event) | ||
log(event, 'emitted', event) | ||
return event | ||
@@ -47,0 +53,0 @@ } |
@@ -15,5 +15,8 @@ var guid = 0 | ||
, ERRORS.invalidName, name) | ||
return flow.name.value = name, flow | ||
var previousName = flow.name.value | ||
flow.name.value = name | ||
dispatchInternalEvent(flow, 'name', name, previousName) | ||
return flow | ||
} | ||
flow.name(name || flow.guid()) | ||
flow.name.value = name || flow.guid() | ||
flow.name.isFlow = true | ||
@@ -20,0 +23,0 @@ flow.name.isInternal = false |
@@ -47,2 +47,3 @@ /** | ||
instance.logger | ||
&& !isInternal(flow) | ||
&& instance.logger(flow, name, newData, oldData) | ||
@@ -49,0 +50,0 @@ } |
@@ -29,4 +29,18 @@ | ||
describe('data API', function(){ | ||
describe('.create() API', function(){ | ||
it('should reuse existing flow objects', function(){ | ||
var sut1 = testFlow.create('test') | ||
var sut2 = testFlow.create('test') | ||
expect(sut1).to.equal(sut2) | ||
}) | ||
it('should NOT reuse existing flow objects for unnamed flow objects', function(){ | ||
var sut1 = testFlow.create() | ||
var sut2 = testFlow.create() | ||
expect(sut1).to.not.equal(sut2) | ||
}) | ||
}) | ||
describe('creating flow objects with data', function(){ | ||
it('should default to undefined', function(){ | ||
@@ -33,0 +47,0 @@ var sut = testFlow.create('test') |
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
79940
1561