PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 All 257 releases
give / src / DonationForms / resources / app / utilities / PrepareFormData.ts

PrepareFormData.ts in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at src/DonationForms/resources/app/utilities/PrepareFormData.ts

37 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {Form, Group, isGroup, Node} from '@givewp/forms/types';
2 import {mapGroup, reduceGroup, walkGroup} from './groups';
3
4 /**
5 * Receives the form data as provided directly from the server and mutates it to be ready for use by the React application
6 *
7 * @since 3.0.0
8 */
9 export default function prepareFormData(form: Form) {
10 form.walkNodes = walkGroupNodes.bind(form);
11 form.mapNodes = mapGroupNodes.bind(form);
12 form.reduceNodes = reduceGroupNodes.bind(form);
13
14 form.walkNodes((node: Group) => {
15 node.walkNodes = walkGroupNodes.bind(node);
16 node.mapNodes = mapGroupNodes.bind(node);
17 node.reduceNodes = reduceGroupNodes.bind(node);
18 }, isGroup);
19 }
20
21 function walkGroupNodes(this: Group, callback: (node: Node) => void, filter?: (node: Node) => boolean) {
22 walkGroup(this, callback, filter);
23 }
24
25 function mapGroupNodes(this: Group, callback: (node: Node) => void, filter?: (node: Node) => boolean) {
26 return mapGroup(this, callback, filter);
27 }
28
29 function reduceGroupNodes(
30 this: Group,
31 callback: (accumulator: any, node: Node) => any,
32 initialValue: any,
33 filter?: (node: Node) => boolean
34 ) {
35 return reduceGroup(this, callback, initialValue, filter);
36 }
37