UNPKG

json-joy

Version:

Collection of libraries for building collaborative editing apps.

22 lines (21 loc) 736 B
import { $$find } from '@jsonjoy.com/json-pointer/lib/codegen/find'; import { deepEqualCodegen } from '@jsonjoy.com/util/lib/json-equal/deepEqualCodegen'; import { compileClosure } from '@jsonjoy.com/util/lib/codegen'; import { predicateOpWrapper } from '../util'; export const $$test = (op) => { const js = /* js */ ` (function(wrapper){ var find = ${$$find(op.path)}; var deepEqual = ${deepEqualCodegen(op.value)}; return wrapper(function(doc){ var val = find(doc); if (val === undefined) return ${op.not ? 'true' : 'false'}; return ${op.not ? '!' : ''}deepEqual(val); }); })`; return { deps: [predicateOpWrapper], js: js, }; }; export const $test = (op) => compileClosure($$test(op));