Comparing version 0.4.1 to 0.5.0
@@ -22,5 +22,6 @@ var util = require('util'); | ||
Task.prototype.defaultTo = function(value) { | ||
Task.prototype.defaultTo = function(name) { | ||
this.requires(name); | ||
this.onComplete(function(result, results){ | ||
if(result.value === null || result.value === undefined) result.value = value; | ||
if(result.value === null || result.value === undefined) result.value = results[name]; | ||
}); | ||
@@ -36,3 +37,3 @@ return this; | ||
err = new errors.ArgumentNull(self.name); | ||
err.message = 'Not Found: ' + self.toString(results.value); | ||
err.message = 'Not Found: ' + self.toString(results); | ||
throw err; | ||
@@ -178,3 +179,2 @@ } | ||
result = { value: result }; | ||
results = { value: results }; | ||
var err; | ||
@@ -181,0 +181,0 @@ try { |
@@ -6,3 +6,3 @@ { | ||
"author": "David Fenster <david@dfenster.com>", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
@@ -116,5 +116,5 @@ fnflow | ||
### task.defaultTo(value) | ||
### task.defaultTo(task_name) | ||
Default the result of a task to a specified value if it did not yield one (undefined or null). | ||
Default the result of a task to the result of a task or data if it did not yield one (undefined or null). | ||
@@ -125,6 +125,6 @@ __Example__ | ||
book: new Task(Book.findByTitle, 'title'), | ||
author_name: new Task(Author.getNameById, 'book.author_id').defaultTo('unknown') | ||
author_name: new Task(Author.getNameById, 'book.author_id').defaultTo('unknown_title') | ||
}); | ||
flow.execute({ title: 'Beowulf' }, function(err, results){ | ||
flow.execute({ title: 'Beowulf', unknown_title: 'unknown' }, function(err, results){ | ||
if(err) return console.error(err); | ||
@@ -131,0 +131,0 @@ console.log(results.author_name + " wrote " + results.title); //prints "unknown wrote Beowulf" |
@@ -20,5 +20,6 @@ var Flow = require('../lib/fnFlow').Flow, Task = Flow.Task; | ||
new Flow({ | ||
book: new Task(Book.getById, 'bookId').defaultTo("none") | ||
book: new Task(Book.getById, 'bookId').defaultTo("default_book") | ||
}).execute({ | ||
bookId: 100 | ||
bookId: 100, | ||
default_book: 'none' | ||
}, function(err, results){ | ||
@@ -33,5 +34,6 @@ test.ok(!err, 'no error'); | ||
new Flow({ | ||
book: new Task(Book.getById, 'bookId').defaultTo("none") | ||
book: new Task(Book.getById, 'bookId').defaultTo("default_book") | ||
}).execute({ | ||
bookId: 1 | ||
bookId: 1, | ||
default_book: 'none' | ||
}, function(err, results){ | ||
@@ -38,0 +40,0 @@ test.ok(!err, 'no error'); |
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
111296
1805