Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 4656028

Browse files
committed
refactore: api
1 parent 65f7549 commit 4656028

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

src/createJsonLogic.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import isLogic from './isLogic';
22
import getOperator from './getOperator';
33

4-
function createJsonLogic() {
5-
const operations = {}
6-
const visitors = {}
4+
function createJsonLogic(operations = {}, visitors = {}) {
5+
Object.keys(operations).forEach(function(name) {
6+
const operation = operations[name];
7+
8+
addOperation(operation.code || name , operation);
9+
});
10+
11+
Object.keys(visitors).forEach(function(name) {
12+
const visitor = visitors[name];
13+
14+
addVisitor(visitor.code || name , visitor);
15+
});
716

817
function addOperation(name, code) {
918
operations[name] = code;
@@ -91,7 +100,7 @@ function createJsonLogic() {
91100
rm_operation: removeOperation,
92101
add_visitor: addVisitor,
93102
rm_visitor: removeVisitor,
94-
}
103+
};
95104
}
96105

97106
export default createJsonLogic;

src/index.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,7 @@ import getValues from "./helpers/getValues";
88
import usesData from "./helpers/usesData";
99
import ruleLike from "./helpers/ruleLike";
1010

11-
const jsonLogic = createJsonLogic();
12-
13-
Object.keys(operations).forEach(function(name) {
14-
const operation = operations[name];
15-
16-
jsonLogic.add_operation(operation.code || name , operation);
17-
});
18-
19-
Object.keys(visitors).forEach(function(name) {
20-
const visitor = visitors[name];
21-
22-
jsonLogic.add_visitor(visitor.code || name , visitor);
23-
});
11+
const jsonLogic = createJsonLogic(operations, visitors);
2412

2513
// restore original public API
2614
jsonLogic.is_logic = isLogic;

0 commit comments

Comments
 (0)