fixes #20 ; on any change API
This commit is contained in:
parent
5ad39791ca
commit
533a28d348
@ -16,19 +16,25 @@ module.exports = () => {
|
||||
|
||||
const triee = new EventEmitter();
|
||||
const triemit = triee.emit.bind(triee);
|
||||
let triemit2 = triemit;
|
||||
|
||||
const cxt = lib.init(lifemit, triemit, info);
|
||||
|
||||
s._write = function (chunk, encoding, callback) {
|
||||
lib.execute(cxt, lifemit, triemit, info, chunk);
|
||||
lib.execute(cxt, lifemit, triemit2, info, chunk);
|
||||
callback();
|
||||
};
|
||||
|
||||
s.change = {
|
||||
on: (id, fn) => {
|
||||
triemit2 = triemit;
|
||||
triee.on(id, fn);
|
||||
const triggerString = triee.eventNames().join(' ') + ' ';
|
||||
lib.setTrigger(cxt, triggerString);
|
||||
},
|
||||
any: fn => {
|
||||
triemit2 = fn;
|
||||
lib.setTrigger(cxt, '\0');
|
||||
}
|
||||
};
|
||||
|
||||
|
43
test/any.js
Normal file
43
test/any.js
Normal file
@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const lib = require('../lib/index.js');
|
||||
|
||||
describe('any', () => {
|
||||
|
||||
it('simple', done => {
|
||||
const inst = lib.parser();
|
||||
const dump = [];
|
||||
inst.change.any((id, time, cmd, value, mask) => {
|
||||
dump.push({
|
||||
id, time, cmd, value, mask
|
||||
});
|
||||
});
|
||||
|
||||
inst.on('finish', () => {
|
||||
expect(dump).to.deep.eq([
|
||||
{ id: 'ABC', time: 100, cmd: 14, value: 0n, mask: 0n },
|
||||
{ id: '123', time: 200, cmd: 15, value: 1n, mask: 0n },
|
||||
{ id: 'XyZ', time: 300, cmd: 14, value: 0n, mask: 0n },
|
||||
{ id: 'foo', time: 400, cmd: 15, value: 1n, mask: 0n },
|
||||
])
|
||||
// console.log(dump);
|
||||
done();
|
||||
});
|
||||
|
||||
inst.write(`\
|
||||
$enddefinitions $end
|
||||
#100
|
||||
0ABC
|
||||
#200
|
||||
1123
|
||||
#300
|
||||
0XyZ
|
||||
#400
|
||||
1foo
|
||||
`);
|
||||
inst.end();
|
||||
});
|
||||
});
|
||||
|
||||
/* eslint-env mocha */
|
@ -25,6 +25,9 @@ int stringEq (
|
||||
const unsigned char* p,
|
||||
const unsigned char* endp
|
||||
) {
|
||||
if (gold[0] == 0) {
|
||||
return 1;
|
||||
}
|
||||
unsigned char* i;
|
||||
unsigned char* j;
|
||||
i = gold;
|
||||
|
Loading…
x
Reference in New Issue
Block a user