Skip to content

Commit e7c3ebd

Browse files
getMappingEvent live examples
1 parent de119bb commit e7c3ebd

File tree

1 file changed

+55
-53
lines changed

1 file changed

+55
-53
lines changed

website/docs/utils/mapping.mdx

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ sidebar_position: 5
55

66
import Link from '@docusaurus/Link';
77
import { LiveCode } from '@site/src/components/organisms/liveCode';
8-
import { getMappingValue } from '@elbwalker/utils';
8+
import { getMappingEvent, getMappingValue } from '@elbwalker/utils';
99
import { parseInput } from '@site/src/components/molecules/codeBox';
10-
export const logFn = (input, config, log) => {
10+
export const logEvent = (input, config, log) => {
11+
log(parseInput(input, { getMappingEvent }));
12+
};
13+
export const logValue = (input, config, log) => {
1114
log(parseInput(input, { getMappingValue }));
1215
};
1316

@@ -22,28 +25,6 @@ a `Mapping.Value` settings for a specific property to return an actual value.
2225
The `custom` property is used by
2326
each&nbsp;<Link to="/docs/destinations/">destination</Link> individually.
2427

25-
```ts
26-
// @TODO update me
27-
const mapping: Config = {
28-
entity: {
29-
action: { name: 'entity_action' }, // Explicit EventConfig
30-
'*': {}, // Generic EventConfig for all entity entities
31-
},
32-
order: {
33-
complete: [
34-
{
35-
// EventConfig only for production
36-
condition: (event: WalkerOS.PartialEvent) =>
37-
event.globals?.env === 'prod',
38-
ignore: true,
39-
},
40-
{ name: 'purchase' }, // Fallback EventConfig
41-
],
42-
},
43-
'*': { '*': { ignore: true } },
44-
};
45-
```
46-
4728
## getMappingEvent
4829

4930
`getMappingEvent(event: string, mapping?: Mapping.Config<unknown>): EventMapping`
@@ -53,28 +34,49 @@ empty object. An explicit key is favored over an asterisk `*` key. If available
5334
a `condition` will be checked to determine if the `EventConfig` applies. It's
5435
used by the&nbsp;<Link to="/docs/sources/">sources</Link>.
5536

56-
```ts
57-
// @TODO remove the types?
58-
interface EventMapping {
59-
eventMapping?: Event;
60-
mappingKey?: string;
61-
}
62-
63-
getMappingEvent({ event: 'entity action' }, mapping);
64-
// { eventMapping: { name: 'entity_action' }, mappingKey: 'entity action' }
65-
66-
getMappingEvent({ event: 'entity action' }, mapping);
67-
// { eventMapping: { }, mappingKey: 'entity action' }
68-
69-
getMappingEvent({ event: 'order complete' }, mapping);
70-
// { eventMapping: { name: 'purchase' }, mappingKey: 'order complete' }
37+
<LiveCode
38+
showMiddle={false}
39+
labelInput="Configuration"
40+
input={`getMappingEvent(
41+
{ event: 'entity action' },
42+
{
43+
entity: {
44+
action: { name: 'entity_action' },
45+
},
46+
}
47+
);`}
48+
output={`0`}
49+
fn={logEvent}
50+
/>
7151

72-
getMappingEvent({ event: 'order complete', globals: { env: 'prod' } }, mapping);
73-
// { eventMapping: { ignore: true, condition: Function }, mappingKey: 'order complete' }
52+
Specify multiple `Mapping.EventConfig` as an array and use `condition` to check
53+
which `EventConfig` should be used. To test uncomment the `globals` property.
7454

75-
getMappingEvent({ event: 'page view' }, mapping);
76-
// { eventMapping: { ignore: true }, mappingKey: 'page view' }
77-
```
55+
<LiveCode
56+
showMiddle={false}
57+
labelInput="Configuration"
58+
input={`getMappingEvent(
59+
{
60+
event: 'order complete',
61+
// globals: { env: 'prod' },
62+
},
63+
{
64+
order: {
65+
complete: [
66+
{
67+
// EventConfig only for production
68+
condition: (event) =>
69+
event.globals?.env === 'prod',
70+
ignore: true,
71+
},
72+
{ name: 'purchase' }, // Fallback EventConfig
73+
],
74+
},
75+
}
76+
);`}
77+
output={`0`}
78+
fn={logEvent}
79+
/>
7880

7981
## getMappingValue
8082

@@ -94,7 +96,7 @@ to standard fields of the destination.
9496
'b',
9597
)`}
9698
output={`0`}
97-
fn={logFn}
99+
fn={logValue}
98100
/>
99101

100102
<LiveCode
@@ -105,7 +107,7 @@ to standard fields of the destination.
105107
'arr.1',
106108
);`}
107109
output={`"bar"`}
108-
fn={logFn}
110+
fn={logValue}
109111
/>
110112

111113
### key
@@ -118,7 +120,7 @@ to standard fields of the destination.
118120
{ key: 'foo' },
119121
);`}
120122
output={`"bar"`}
121-
fn={logFn}
123+
fn={logValue}
122124
/>
123125

124126
### value
@@ -128,7 +130,7 @@ to standard fields of the destination.
128130
labelInput="Configuration"
129131
input={`getMappingValue({}, { value: 'foo' });`}
130132
output={`"foo"`}
131-
fn={logFn}
133+
fn={logValue}
132134
/>
133135

134136
### fn
@@ -141,7 +143,7 @@ to standard fields of the destination.
141143
{ fn: (obj) => obj.foo.toUpperCase() },
142144
);`}
143145
output={`"BAR"`}
144-
fn={logFn}
146+
fn={logValue}
145147
/>
146148

147149
### map
@@ -164,7 +166,7 @@ to standard fields of the destination.
164166
bar: 'baz',
165167
obj: { recursive: true },
166168
}`}
167-
fn={logFn}
169+
fn={logValue}
168170
/>
169171

170172
### loop
@@ -177,7 +179,7 @@ to standard fields of the destination.
177179
{ loop: ['arr', 'id'] },
178180
);`}
179181
output={`['foo', 'bar']`}
180-
fn={logFn}
182+
fn={logValue}
181183
/>
182184

183185
### validate
@@ -187,7 +189,7 @@ to standard fields of the destination.
187189
labelInput="Configuration"
188190
input={`getMappingValue({ foo: 'bar' }, { key: 'foo', validate: (v) => v === 'bar' });`}
189191
output={`"bar"`}
190-
fn={logFn}
192+
fn={logValue}
191193
/>
192194

193195
### consent
@@ -201,7 +203,7 @@ to standard fields of the destination.
201203
{ instance }, // instance with consent state
202204
);`}
203205
output={`undefined (no marketing required consent)`}
204-
fn={logFn}
206+
fn={logValue}
205207
/>
206208

207209
First the `condition` is checked to determine if the `ValueConfig` should be

0 commit comments

Comments
 (0)