Skip to content

Commit b7f942b

Browse files
committed
factMapId instead of id - id (and similar names) seems like it would be common enough to be passed in context, a gross name like factMapId should be less bothersome
1 parent c3260b9 commit b7f942b

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ The `then` or `otherwise` property can consist of either `actions`, but it can a
233233
const myRule = {
234234
when: [
235235
{
236-
id: 'weatherCondition',
236+
factMapId: 'weatherCondition',
237237
weather: {
238238
params: {
239239
query: '{{city}}',
@@ -302,7 +302,7 @@ const myRule = {
302302

303303
A fact map is a plain object whose keys are facts (static or functional) and values are [`Evaluator`'s](#evaluator).
304304

305-
NOTE: `id` is a reserved word in a `FactMap`. It is used internally to allow easy access to the results of a `FactMap` for interpolation in the `then` or `otherwise` clauses.
305+
**NOTE: `factMapId` is a reserved word in a `FactMap`. It is used internally to allow easy access to the results of a `FactMap` for interpolation in the `then` or `otherwise` clauses. For this reason `factMapId` _CANNOT_ be given as a fact or context**.
306306

307307
#### Evaluator
308308

src/evaluator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const createEvaluator =
22
(validator, opts, emit, rule) =>
3-
(id) =>
3+
(factMapId) =>
44
async ([factName, { params, path, is }]) => {
5-
const onError = (params) => emit('error', { ...params, rule, id });
5+
const onError = (params) => emit('error', { ...params, rule, factMapId });
66

77
const fact = opts.facts[factName] || opts.context[factName];
88
try {

src/fact.map.processor.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ import { createEvaluator } from './evaluator';
33
export const createFactMapProcessor = (validator, opts, emit) => (rule) => {
44
const evaluator = createEvaluator(validator, opts, emit, rule);
55
return async (factMap, index) => {
6-
// id is a reserved word
7-
const { id = index, ...map } = factMap;
6+
// factMapId is a reserved word
7+
const { factMapId = index, ...map } = factMap;
88

99
// flags for if there was an error processing the fact map
1010
// and if all evaluations in the fact map passed
1111
let error = false;
1212
let passed = true;
1313

1414
const results = (
15-
await Promise.all(Object.entries(map).map(evaluator(id)))
15+
await Promise.all(Object.entries(map).map(evaluator(factMapId)))
1616
).reduce((acc, { factName, ...rest }) => {
1717
if (error) return acc;
1818
error = error || !!rest.error;
@@ -23,7 +23,7 @@ export const createFactMapProcessor = (validator, opts, emit) => (rule) => {
2323

2424
// return the results in the same form they were passed in
2525
return {
26-
[id]: {
26+
[factMapId]: {
2727
...results,
2828
__passed: passed,
2929
__error: error,

0 commit comments

Comments
 (0)