Prism · Transform
$walk
Visits every node of a tree, at any depth, and replaces a node with the first rule whose when holds for it. Children are rewritten before their parent unless order is pre. A walk visits objects and lists as well as leaves, so a rule for strings checks the type first.
{
document: {
component: 'Stack',
children: [
{ component: 'Text', children: '{{$.q}}' },
{ component: 'Field', props: { value: '$.q' } },
],
},
}{
$walk: {
over: { $ref: '$.document' },
as: 'n',
rules: [
{
when: { $eq: [{ $var: 'n' }, { $const: '$.q' }] },
then: { $const: '$.search' },
},
{
when: { $eq: [{ $var: 'n' }, { $const: '{{$.q}}' }] },
then: { $const: '{{$.search}}' },
},
],
},
}{
component: 'Stack',
children: [
{ component: 'Text', children: '{{$.search}}' },
{ component: 'Field', props: { value: '$.search' } },
],
}Runs in this page on the installed package. The input and the expected output are defined by the example.