-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
55 lines (50 loc) · 1.15 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { renderForm } from './src/dform'
const schema = {
cond: {
type: 'equals',
field_id: 'showForm',
field_value: true,
},
fields: [{
type: 'boolean',
id: 'input1',
}, {
type: 'string',
id: 'input2'
}],
children: [{
cond: {
type: 'and',
conds: [{
type: 'truthy',
field_id: 'input1',
}, {
type: 'not_empty',
field_id: 'input2',
}],
},
fields: [{
type: 'boolean',
id: 'input3',
}],
}],
}
const inputFactories = {
'boolean': args => `<BooleanInput id=${args.id}>`,
'string': args => `<StringInput id=${args.id}>`,
}
const state = {
showForm: true,
input1: true,
input2: 'Some string',
}
console.log(renderForm(state, schema, inputFactories))
// [ '<BooleanInput id=input1>',
// '<StringInput id=input2>',
// '<BooleanInput id=input3>' ]
state.input1 = false
console.log(renderForm(state, schema, inputFactories))
// [ '<BooleanInput id=input1>', '<StringInput id=input2>' ]
state.showForm = false
console.log(renderForm(state, schema, inputFactories))
// []