Skip to content

Commit cd78db5

Browse files
committed
fix #8
1 parent b48735a commit cd78db5

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

+32-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ npm install --s json-rules-engine-simplified
3131
The simplest example of using `json-rules-engine-simplified`
3232

3333
```jsx
34-
import { Engine } from 'json-rules-engine-simplified'
34+
import Engine from 'json-rules-engine-simplified'
3535

3636
let rules = [{
3737
conditions: {
@@ -65,6 +65,37 @@ engine
6565

6666
Rules engine expects to know all the rules in advance, it effectively drops builder pattern, but keeps the interface.
6767

68+
### Appending rule to existing engine
69+
70+
You don't have to specify all rules at the construction time, you can add rules in different time in process.
71+
In order to add new rules to the `Engine` use `addRule` function.
72+
73+
For example, following declarations are the same
74+
```js
75+
import Engine from 'json-rules-engine-simplified';
76+
77+
let engineA = new Engine();
78+
79+
let rule = {
80+
conditions: {
81+
firstName: "empty"
82+
},
83+
event: {
84+
type: "remove",
85+
params: {
86+
field: "password"
87+
},
88+
}
89+
};
90+
91+
engineA.addRule(rule);
92+
93+
let engineB = new Engine(rule);
94+
95+
```
96+
97+
In this case `engineA` and `engineB` will give the same results.
98+
6899
## Validation
69100

70101
In order to prevent most common errors, `Engine` does initial validation on the schema, during construction.

0 commit comments

Comments
 (0)