Skip to content

Commit

Permalink
Merge pull request #504 from senecajs/remove-pin
Browse files Browse the repository at this point in the history
[WIP] Remove Pin functionality.
  • Loading branch information
mcdonnelldean authored Aug 23, 2016
2 parents 824e7f0 + 40f2905 commit 926802c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 348 deletions.
79 changes: 0 additions & 79 deletions seneca.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
174 changes: 0 additions & 174 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ describe('plugin', function () {
})
})


it('dynamic-load-sequence', function (done) {
var a = []
Seneca({log: 'test', debug: {undead: true}})
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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()
})
})
})
Loading

0 comments on commit 926802c

Please sign in to comment.