Skip to content

Commit c5c11e0

Browse files
committed
Simplify runners in defaultMethods
1 parent f2d376c commit c5c11e0

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

async_optimizer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function getMethod (logic, engine, methodName, above) {
1919
if (method.traverse === false) {
2020
if (typeof method[Sync] === 'function' && method[Sync](logic, { engine })) {
2121
const called = method.method ? method.method : method
22-
return declareSync((data, abv) => called(logic[methodName], data, abv || above, engine), true)
22+
return declareSync((data, abv) => called(logic[methodName], data, abv || above, engine.fallback), true)
2323
}
2424

2525
const args = logic[methodName]
@@ -35,7 +35,7 @@ function getMethod (logic, engine, methodName, above) {
3535
const called = method.method ? method.method : method
3636
return declareSync((data, abv) => {
3737
const evaluatedArgs = optimizedArgs.map(l => typeof l === 'function' ? l(data, abv) : l)
38-
return called(evaluatedArgs, data, abv || above, engine)
38+
return called(evaluatedArgs, data, abv || above, engine.fallback)
3939
}, true)
4040
}
4141

defaultMethods.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const defaultMethods = {
9595
method: (input, context, above, engine) => {
9696
if (!Array.isArray(input)) throw new InvalidControlInput(input)
9797

98-
if (input.length === 1) return (engine.fallback || engine).run(input[0], context, { above })
98+
if (input.length === 1) return engine.run(input[0], context, { above })
9999
if (input.length < 2) return null
100100

101101
input = [...input]
@@ -109,13 +109,13 @@ const defaultMethods = {
109109
const check = input.shift()
110110
const onTrue = input.shift()
111111

112-
const test = (engine.fallback || engine).run(check, context, { above })
112+
const test = engine.run(check, context, { above })
113113

114114
// if the condition is true, run the true branch
115-
if (engine.truthy(test)) return (engine.fallback || engine).run(onTrue, context, { above })
115+
if (engine.truthy(test)) return engine.run(onTrue, context, { above })
116116
}
117117

118-
return (engine.fallback || engine).run(onFalse, context, { above })
118+
return engine.run(onFalse, context, { above })
119119
},
120120
[Sync]: (data, buildState) => isSyncDeep(data, buildState.engine, buildState),
121121
deterministic: (data, buildState) => {
@@ -330,15 +330,15 @@ const defaultMethods = {
330330
method: (input, context, above, engine) => {
331331
if (!Array.isArray(input)) throw new InvalidControlInput(input)
332332
let [selector, mapper, defaultValue] = input
333-
defaultValue = (engine.fallback || engine).run(defaultValue, context, {
333+
defaultValue = engine.run(defaultValue, context, {
334334
above
335335
})
336336
selector =
337-
(engine.fallback || engine).run(selector, context, {
337+
engine.run(selector, context, {
338338
above
339339
}) || []
340340
const func = (accumulator, current) => {
341-
return (engine.fallback || engine).run(
341+
return engine.run(
342342
mapper,
343343
{
344344
accumulator,
@@ -398,8 +398,8 @@ const defaultMethods = {
398398
[Sync]: (data, buildState) => isSyncDeep(data, buildState.engine, buildState),
399399
method: (args, context, above, engine) => {
400400
if (!Array.isArray(args)) throw new Error('Data for pipe must be an array')
401-
let answer = (engine.fallback || engine).run(args[0], context, { above: [args, context, ...above] })
402-
for (let i = 1; i < args.length; i++) answer = (engine.fallback || engine).run(args[i], answer, { above: [args, context, ...above] })
401+
let answer = engine.run(args[0], context, { above: [args, context, ...above] })
402+
for (let i = 1; i < args.length; i++) answer = engine.run(args[i], answer, { above: [args, context, ...above] })
403403
return answer
404404
},
405405
asyncMethod: async (args, context, above, engine) => {
@@ -428,7 +428,7 @@ const defaultMethods = {
428428
const item = object[key]
429429
Object.defineProperty(accumulator, key, {
430430
enumerable: true,
431-
value: (engine.fallback || engine).run(item, context, { above })
431+
value: engine.run(item, context, { above })
432432
})
433433
return accumulator
434434
}, {})
@@ -493,12 +493,12 @@ function createArrayIterativeMethod (name, useTruthy = false) {
493493
if (!Array.isArray(input)) throw new InvalidControlInput(input)
494494
let [selector, mapper] = input
495495
selector =
496-
(engine.fallback || engine).run(selector, context, {
496+
engine.run(selector, context, {
497497
above
498498
}) || []
499499

500500
return selector[name]((i, index) => {
501-
const result = (engine.fallback || engine).run(mapper, i, {
501+
const result = engine.run(mapper, i, {
502502
above: [{ item: selector, index }, context, ...above]
503503
})
504504
return useTruthy ? engine.truthy(result) : result

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-logic-engine",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Construct complex rules with JSON & process them.",
55
"main": "./dist/cjs/index.js",
66
"module": "./dist/esm/index.js",

0 commit comments

Comments
 (0)