diff --git a/seneca.js b/seneca.js index e8aeaf68..21ea1876 100644 --- a/seneca.js +++ b/seneca.js @@ -151,11 +151,6 @@ var internals = { running: false }, - pin: { - // run pin function without waiting for pin event - immediate: false - }, - // backwards compatibility settings legacy: { // use old error codes, until version 3.x @@ -310,7 +305,6 @@ function make_seneca (initial_options) { // Non-API methods. root.register = Plugins.register(so, callpoint) root.depends = api_depends - root.pin = api_pin root.act_if = api_act_if root.wrap = api_wrap root.seneca = api_seneca @@ -454,75 +448,6 @@ function make_seneca (initial_options) { return exportval } - // TODO: DEPRECATE - function api_pin (pattern, pinopts) { - var thispin = this - - pattern = _.isString(pattern) ? Jsonic(pattern) : pattern - - var methodkeys = [] - for (var key in pattern) { - if (/[\*\?]/.exec(pattern[key])) { - methodkeys.push(key) - } - } - - function make_pin (pattern) { - var api = { - toString: function () { - return 'pin:' + Common.pattern(pattern) + '/' + thispin - } - } - - var calcPin = function () { - var methods = private$.actrouter.list(pattern) - - methods.forEach(function (method) { - var mpat = method.match - - var methodname = '' - for (var mkI = 0; mkI < methodkeys.length; mkI++) { - methodname += ((mkI > 0 ? '_' : '')) + mpat[methodkeys[mkI]] - } - - api[methodname] = function (args, cb) { - var si = this && this.seneca ? this : thispin - - var fullargs = _.extend({}, args, mpat) - si.act(fullargs, cb) - } - - api[methodname].pattern$ = method.match - api[methodname].name$ = methodname - }) - - if (pinopts && pinopts.include) { - for (var i = 0; i < pinopts.include.length; i++) { - var methodname = pinopts.include[i] - if (thispin[methodname]) { - api[methodname] = Common.delegate(thispin, thispin[methodname]) - } - } - } - } - - var opts = {} - _.defaults(opts, pinopts, so.pin) - - if (private$._isReady || opts.immediate) { - calcPin() - } - else { - root.once('pin', calcPin) - } - - return api - } - - return make_pin(pattern) - } - - function api_sub () { var self = this @@ -1776,10 +1701,6 @@ function make_seneca (initial_options) { function action_queue_clear () { root.emit('ready') - // DEPRECATED, removed in Seneca 3.0 - root.emit('pin') - root.emit('after-pin') - var ready = root.private$.ready_list.shift() if (ready) { ready() diff --git a/test/plugin.test.js b/test/plugin.test.js index 03c625ba..2e3ff75a 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -379,7 +379,6 @@ describe('plugin', function () { }) }) - it('dynamic-load-sequence', function (done) { var a = [] Seneca({log: 'test', debug: {undead: true}}) @@ -444,7 +443,6 @@ describe('plugin', function () { }) }) - it('plugin options can be modified by plugins during load sequence', function (done) { var seneca = Seneca({ log: 'test', @@ -548,176 +546,4 @@ describe('plugin', function () { done() }) }) - - it('will be able to pin with multiple plugins and local immediate setting', function (done) { - var seneca = Seneca({ log: 'silent' }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }, { immediate: true }) - api.msA1({ msg: 'hi' }, function (err, message) { - expect(err).to.not.exist() - expect(message.result).to.equal('msa1') - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - var pluginC = function () { - this.add({ init: 'pluginC' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ cmd: 'msC1' }, function (msg, cb) { - cb(null, { result: 'msC1' }) - }) - - return { - name: 'pluginC' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.use(pluginC) - seneca.ready(function () { - done() - }) - }) - - it('will be able to pin with multiple plugins and seneca pin immediate setting', function (done) { - var seneca = Seneca({ log: 'silent', pin: { immediate: true } }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }) - api.msA1({ msg: 'hi' }, function (err, message) { - expect(err).to.not.exist() - expect(message.result).to.equal('msa1') - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - var pluginC = function () { - this.add({ init: 'pluginC' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ cmd: 'msC1' }, function (msg, cb) { - cb(null, { result: 'msC1' }) - }) - - return { - name: 'pluginC' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.use(pluginC) - seneca.ready(function () { - done() - }) - }) - - it('pinning waits for ready by default', function (done) { - var seneca = Seneca({ log: 'silent' }) - - var pluginA = function () { - this.add({ init: 'pluginA' }, function (msg, cb) { - process.nextTick(cb) - }) - - this.add({ role: 'pluginA', cmd: 'msA1' }, function (msg, cb) { - cb(null, { result: 'msA1' }) - }) - - this.add({ role: 'pluginA', cmd: 'msA2' }, function (msg, cb) { - cb(null, { result: 'msA2' }) - }) - - return { - name: 'pluginA' - } - } - - var pluginB = function () { - this.add({ init: 'pluginB' }, function (msg, cb) { - var api = this.pin({ role: 'pluginA', cmd: '*' }) - expect(api.msA1).to.not.exist() - this.once('ping', function () { - api = this.pin({ role: 'pluginA', cmd: '*' }) - expect(api.msA1).to.exist() - }) - cb() - }) - - this.add({ cmd: 'msB1' }, function (msg, cb) { - cb(null, { result: 'msB1' }) - }) - - return { - name: 'pluginB' - } - } - - seneca.use(pluginA) - seneca.use(pluginB) - seneca.ready(function () { - done() - }) - }) }) diff --git a/test/seneca.test.js b/test/seneca.test.js index 9e6bd56a..b44eacc2 100644 --- a/test/seneca.test.js +++ b/test/seneca.test.js @@ -652,68 +652,6 @@ describe('seneca', function () { done() }) - it('pin', function (done) { - var si = Seneca({log: 'silent'}) - - var log = [] - - si.add({p1: 'v1', p2: 'v2a'}, function (args, cb) { - log.push('a' + args.p3) - cb(null, {p3: args.p3}) - }) - - si.add({p1: 'v1', p2: 'v2b'}, function (args, cb) { - log.push('b' + args.p3) - cb(null, {p3: args.p3}) - }) - - var api = si.pin({p1: 'v1', p2: '*'}) - - si.ready(function () { - api.v2a({p3: 'A'}, function (err, r) { - assert.equal(err, null) - assert.equal(r.p3, 'A') - }) - api.v2b({p3: 'B'}, function (err, r) { - assert.equal(err, null) - assert.equal(r.p3, 'B') - }) - - var acts = si.pinact({p1: 'v1', p2: '*'}) - assert.equal("[ { p1: 'v1', p2: 'v2a' }, { p1: 'v1', p2: 'v2b' } ]", - Util.inspect(acts)) - - done() - }) - }) - - it('pin-star', function (done) { - var si = Seneca(testopts) - - si.add('a:1,b:x', function () {}) - si.add('a:1,c:y', function () {}) - var pin_b = si.pin('a:1,b:*') - var pin_c = si.pin('a:1,c:*') - - si.ready(function () { - assert.ok(_.isFunction(pin_b.x)) - assert.equal(pin_b.y, null) - assert.ok(_.isFunction(pin_c.y)) - assert.equal(pin_c.x, null) - - assert.deepEqual([ { a: '1', b: 'x' }, { a: '1', c: 'y' } ], - si.findpins('a:1')) - - assert.deepEqual([ { a: '1', b: 'x' } ], - si.findpins('a:1,b:*')) - - assert.deepEqual([ { a: '1', c: 'y' } ], - si.findpins('a:1,c:*')) - - done() - }) - }) - it('fire-and-forget', function (done) { var si = Seneca({log: 'silent'}) si.add({a: 1}, function (args, cb) { cb(null, args.a + 1) }) @@ -1361,37 +1299,4 @@ describe('seneca', function () { done() }) }) - -/* - it('depth0-loop', function (done) { - Seneca({ log: 'silent', strict: { maxloop: 0 } }) - .add('a:1', function (msg, done) { - this.act('a:1', function (err, out) { - done(err, out) - }) - }) - .act('a:1', function (err) { - expect(err).to.exist() - expect(err.code).to.equal('act_loop') - done() - }) - }) - - it('depth3-loop', function (done) { - var count = 0 - Seneca({ log: 'silent', strict: { maxloop: 3 } }) - .add('a:1', function (msg, done) { - ++count - this.act('a:1', function (err, out) { - done(err, out) - }) - }) - .act('a:1', function (err) { - expect(err).to.exist() - expect(err.code).to.equal('act_loop') - expect(count).to.equal(4) - done() - }) - }) -*/ })