Permalink
Browse files

using ordu

  • Loading branch information...
1 parent f7e5784 commit 700c5003b17e87af8156a3ddc9a098d08a9152ad @rjrodger rjrodger committed Sep 16, 2016
Showing with 14 additions and 171 deletions.
  1. +1 −1 .eslintrc
  2. +0 −84 lib/ward.js
  3. +3 −2 package.json
  4. +10 −10 seneca.js
  5. +0 −74 test/ward.test.js
View
@@ -1,3 +1,3 @@
{
"extends": "seneca"
-}
+}
View
@@ -1,84 +0,0 @@
-/* Copyright (c) 2016 Richard Rodger and other contributors, MIT License */
-'use strict'
-
-// To test separately:
-// $ ./node_modules/.bin/lab -v -P ward -t 100 -L -g ward
-
-var Assert = require('assert')
-
-
-module.exports = function (opts) {
- return new Ward(opts)
-}
-
-
-var wardI = -1
-
-
-function Ward (opts) {
- var self = this
- ++wardI
-
-
- opts = opts || {}
- Assert('object' === typeof opts)
-
- opts.name = opts.name || 'ward' + wardI
-
-
- self.add = api_add
- self.process = api_process
- self.tasknames = api_tasknames
- self.toString = api_toString
-
-
- var tasks = []
-
-
- function api_add (task) {
- Assert('function' === typeof task)
-
- if (!task.name) {
- Object.defineProperty(task, 'name', {
- value: opts.name + '_task' + tasks.length
- })
- }
-
- tasks.push(task)
- }
-
-
- function api_process (ctxt, data) {
- for (var tI = 0; tI < tasks.length; ++tI) {
- var index$ = tI
- var taskname$ = tasks[tI].name
-
- ctxt.index$ = index$
- ctxt.taskname$ = taskname$
-
- var res = tasks[tI].call(null, ctxt, data)
-
- if (res) {
- res.index$ = index$
- res.taskname$ = taskname$
- res.ctxt$ = ctxt
- res.data$ = data
- return res
- }
- }
- }
-
-
- function api_tasknames () {
- return tasks.map(function (v) {
- return v.name
- })
- }
-
-
- function api_toString () {
- return opts.name + ':[' + self.tasknames() + ']'
- }
-
- return self
-}
View
@@ -85,12 +85,13 @@
"minimist": "1.2.0",
"nid": "0.3.2",
"norma": "0.3.0",
+ "ordu": "0.0.1",
"patrun": "0.5.1",
"rolling-stats": "0.1.1",
"semver": "5.3.0",
+ "seneca-log-filter": "0.1.0",
"seneca-transport": "2.1.0",
- "use-plugin": "0.3.1",
- "seneca-log-filter": "0.1.0"
+ "use-plugin": "0.3.1"
},
"devDependencies": {
"async": "2.0.x",
View
@@ -17,12 +17,12 @@ var Nid = require('nid')
var Norma = require('norma')
var Patrun = require('patrun')
var Stats = require('rolling-stats')
+var Ordu = require('ordu')
// Internal modules.
var Actions = require('./lib/actions')
var Common = require('./lib/common')
-var Ward = require('./lib/ward')
var Errors = require('./lib/errors')
var Legacy = require('./lib/legacy')
var Optioner = require('./lib/optioner')
@@ -412,7 +412,7 @@ function make_seneca (initial_options) {
private$.ready_list = []
- private$.inward = Ward({name: 'inward'})
+ private$.inward = Ordu({name: 'inward'})
private$.inward.add(Actions.inward.act_default)
private$.inward.add(Actions.inward.act_not_found)
@@ -879,7 +879,7 @@ function make_seneca (initial_options) {
var execute_action = function execute_action (act_instance, action_done) {
actmeta = actmeta || act_instance.find(args, {catchall: so.internal.catchall})
- var wardctxt = {
+ var inwardctxt = {
seneca: act_instance,
actmeta: actmeta,
options: act_instance.options(),
@@ -893,15 +893,15 @@ function make_seneca (initial_options) {
__origargs: origargs
}
var msg = args // _.clone(origmsg)
- var wardres = private$.inward.process(wardctxt, msg)
- // console.log('WARD', actmeta && actmeta.pattern, wardres)
+ var inwardres = private$.inward.process(inwardctxt, msg)
+ // console.log('WARD', actmeta && actmeta.pattern, inwardres)
- if (wardres) {
- if ('error' === wardres.kind) {
- return action_done.call(act_instance, wardres.error)
+ if (inwardres) {
+ if ('error' === inwardres.kind) {
+ return action_done.call(act_instance, inwardres.error)
}
- else if ('result' === wardres.kind) {
- return action_done.call(act_instance, null, wardres.result)
+ else if ('result' === inwardres.kind) {
+ return action_done.call(act_instance, null, inwardres.result)
}
}
View
@@ -1,74 +0,0 @@
-/* Copyright (c) 2016 Richard Rodger, MIT License */
-'use strict'
-
-var Lab = require('lab')
-var Code = require('code')
-var Ward = require('../lib/ward')
-
-
-var lab = exports.lab = Lab.script()
-var describe = lab.describe
-var it = lab.it
-var expect = Code.expect
-
-
-describe('ward', function () {
- it('construct', function (fin) {
- var w = Ward()
- expect(w).to.exist()
-
- var wn = ('' + w).replace(/ward\d+/g, 'ward0')
- expect(wn).to.equal('ward0:[]')
- fin()
- })
-
- it('happy', function (fin) {
- var w = Ward()
-
- w.add(function (ctxt, data) {
- data.x = 1
- })
-
- var ctxt = {}
- var data = {}
-
- expect(data.x).to.not.exist()
-
- var res = w.process(ctxt, data)
-
- expect(res).to.not.exist()
- expect(data.x).to.equal(1)
-
- w.add(function failer (ctxt, data) {
- return {kind: 'error'}
- })
-
- data = {}
- res = w.process(ctxt, data)
-
- expect(data.x).to.equal(1)
- expect(res.kind).to.equal('error')
- expect(res.index$).to.equal(1)
- expect(res.taskname$).to.equal('failer')
- expect(res.ctxt$).to.equal(ctxt)
- expect(res.data$).to.equal(data)
-
- var wn = ('' + w).replace(/ward\d+/g, 'ward1')
- expect(wn).to.equal('ward1:[ward1_task0,failer]')
-
- fin()
- })
-
-
- it('list', function (fin) {
- var w = Ward({name: 'foo'})
-
- w.add(function zero () {})
- w.add(function () {})
- w.add(function two () {})
-
- expect(w.tasknames()).to.equal(['zero', 'foo_task1', 'two'])
- expect('' + w).to.equal('foo:[zero,foo_task1,two]')
- fin()
- })
-})

0 comments on commit 700c500

Please sign in to comment.