Skip to content

Commit

Permalink
Fix spacing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
RDIL committed Nov 25, 2023
1 parent 40d26ad commit dd4813c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 27 deletions.
43 changes: 28 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function testWithPath(input: any, context, options: TestOptions, name: string) {
})
}

function realTest<Variables, Return = Variables | boolean>(
function realTest<Variables>(
input: any,
variables: Variables,
options: TestOptions
Expand Down Expand Up @@ -373,20 +373,29 @@ export function handleActions<Context>(
}
case "$mul": {
// $mul can have 2 or 3 operands, 2 means multiply the context variable (1st operand) by the 2nd operand
let reference = input["$mul"][input["$mul"].length === 3 ? 2 : 0]

let reference =
input["$mul"][input["$mul"].length === 3 ? 2 : 0]

// Therefore the 1st operand might get written to, but the 2nd one is purely a read.
const variableValue1 = findNamedChild(input["$mul"][0], context, true)
const variableValue2 = findNamedChild(input["$mul"][1], context, false)

const variableValue1 = findNamedChild(
input["$mul"][0],
context,
true
)
const variableValue2 = findNamedChild(
input["$mul"][1],
context,
false
)

set(context, reference, variableValue1 * variableValue2)
break
}
case "$set": {
let reference = input.$set[0]

const value = findNamedChild(input.$set[1], context, false)

set(context, reference, value)
break
}
Expand All @@ -400,27 +409,31 @@ export function handleActions<Context>(
}
case "$remove": {
let reference = input.$remove[0]

if (reference.startsWith("$")) {
reference = reference.substring(1)
}

const value = findNamedChild(input.$remove[1], context, false)

// clone the thing
let array: unknown[] = deepClone(
findNamedChild(reference, context, true)
)

array = array.filter((item) => item !== value)

set(context, reference, array)
break
}
case "$reset": {
let reference = input.$reset
const value = findNamedChild(reference, options.originalContext, true)

const value = findNamedChild(
reference,
options.originalContext,
true
)

set(context, reference, value)
break
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export interface HandleActionsOptions {
/**
* The original context, this value is retrieved from
* the definition, and used with the $reset op.
*
*
* @since v5.6.0
*/
originalContext?: unknown
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export function findNamedChild(
}

// Default to the reference itself
return reference
return reference
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/math-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const data = {
],
Inc3: [
{
$inc: ["Counter", "$.Value"]
$inc: ["Counter", "$.Value"],
},
{
Counter: 40,
Value: 2
}
Value: 2,
},
],
Dec1: [
{
Expand Down Expand Up @@ -83,14 +83,14 @@ const data = {
],
Mul2: [
{
$mul: ["Context.Object", 10]
$mul: ["Context.Object", 10],
},
{
Context: {
Object: 42
}
}
]
Object: 42,
},
},
],
}

describe("$inc", () => {
Expand Down
4 changes: 2 additions & 2 deletions tests/reset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const data = {
$reset: "Targets",
},
{
Targets: ["RDIL", "MoonySolari", "Tony"]
Targets: ["RDIL", "MoonySolari", "Tony"],
},
],
Reset2: [
Expand All @@ -33,7 +33,7 @@ const data = {
$reset: "Targets",
},
{
Targets: []
Targets: [],
},
],
}
Expand Down

0 comments on commit dd4813c

Please sign in to comment.