Skip to content

Commit 6bab1e4

Browse files
committed
#6 Updating documentation
1 parent 87a4d89 commit 6bab1e4

File tree

2 files changed

+64
-9
lines changed

2 files changed

+64
-9
lines changed

README.md

+47
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,53 @@ let rules = [{
422422

423423
Rules engine will go through all the elements in the array and trigger `require` if `any` of the elements meet the criteria.
424424

425+
## Events
426+
427+
Framework does not put any restrictions on event object, that will be triggered, in case conditions are meet
428+
429+
For example, `event` can be a string:
430+
```js
431+
let rules = [{
432+
conditions: { ... },
433+
event: "require"
434+
}]
435+
```
436+
Or number
437+
```js
438+
let rules = [{
439+
conditions: { ... },
440+
event: 4
441+
}]
442+
```
443+
444+
Or an `object`
445+
```js
446+
let rules = [{
447+
conditions: { ... },
448+
event: {
449+
type: "require",
450+
params: { fields: [ "state" ]}
451+
}
452+
}]
453+
```
454+
455+
You can even return an array of events, each of which will be added to final array of results
456+
```js
457+
let rules = [{
458+
conditions: { ... },
459+
event: [
460+
{
461+
type: "require",
462+
params: { field: "state"}
463+
},
464+
{
465+
type: "remove",
466+
params: { fields: "fake" }
467+
},
468+
]
469+
}]
470+
```
471+
425472
## License
426473

427474
The project is licensed under the Apache Licence 2.0.
+17-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
import applicableActions from "../src/applicableActions";
22

3-
let rules = [
4-
{
5-
conditions: {
6-
address: "empty",
7-
},
8-
event: [{ type: "remove" }, { type: "add" }],
9-
},
10-
];
11-
123
test("check nested fields work", function() {
4+
let rules = [
5+
{
6+
conditions: { address: "empty" },
7+
event: [{ type: "remove" }, { type: "add" }],
8+
},
9+
];
1310
expect(applicableActions(rules, {})).toEqual([
1411
{ type: "remove" },
1512
{ type: "add" },
1613
]);
1714
expect(applicableActions(rules, { address: { line: "some" } })).toEqual([]);
1815
});
16+
17+
test("check fields of different types", function() {
18+
let rules = [
19+
{
20+
conditions: { address: "empty" },
21+
event: ["remove", 1],
22+
},
23+
];
24+
expect(applicableActions(rules, {})).toEqual(["remove", 1]);
25+
expect(applicableActions(rules, { address: { line: "some" } })).toEqual([]);
26+
});

0 commit comments

Comments
 (0)