Skip to content

Commit

Permalink
fix: rely on equal for computing contains
Browse files Browse the repository at this point in the history
This change allows contains to be computed using the toValue of the items in the array.
Before this change if I had an array of "Drop" `contains` would not match against the value.
  • Loading branch information
santialbo committed Feb 8, 2024
1 parent 4518a19 commit 5c16a4a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/render/operator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isComparable } from '../drop/comparable'
import { Context } from '../context'
import { isFunction, toValue } from '../util'
import { toValue } from '../util'
import { isFalsy, isTruthy } from '../render/boolean'
import { isArray } from '../util/underscore'

Expand Down Expand Up @@ -34,8 +34,7 @@ export const defaultOperators: Operators = {
},
'contains': (l: any, r: any) => {
l = toValue(l)
r = toValue(r)
return l && isFunction(l.indexOf) ? l.indexOf(r) > -1 : false
return l && isArray(l) ? l.some((i) => equal(i, r)) : false
},
'not': (v: any, ctx: Context) => isFalsy(toValue(v), ctx),
'and': (l: any, r: any, ctx: Context) => isTruthy(toValue(l), ctx) && isTruthy(toValue(r), ctx),
Expand Down

0 comments on commit 5c16a4a

Please sign in to comment.