Skip to content
This repository was archived by the owner on Jan 2, 2023. It is now read-only.

Commit 00f0997

Browse files
committed
adds a callback on match
1 parent aebb8e5 commit 00f0997

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

objectron.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const match = (payload, pattern) => {
1+
const match = (payload, pattern, callback) => {
22
let result = { match: true, total: 0, matches: {}, groups: {}};
33
let node = result.matches;
44

@@ -52,7 +52,11 @@ const match = (payload, pattern) => {
5252

5353
tester(payload, pattern, node);
5454

55+
if(callback && result.match){
56+
callback(result);
57+
}
58+
5559
return result;
5660
}
5761

58-
module.exports = match;
62+
module.exports = match;

test/test_objectron.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,4 +327,20 @@ suite('Objectron Core Tests', () => {
327327
assert.isTrue(result.match);
328328
assert.deepEqual(result, expected);
329329
});
330+
331+
test('Callback fired on match', () => {
332+
333+
let called = false;
334+
335+
const payload = {
336+
'type': 'message',
337+
}
338+
339+
const result = match(payload, {
340+
'type': 'message',
341+
},() => called = true);
342+
343+
assert.isTrue(called);
344+
345+
});
330346
});

0 commit comments

Comments
 (0)