Skip to content

Commit cc4d85a

Browse files
committed
chore: log info about micro and macro tasks
1 parent 8c9ecd4 commit cc4d85a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

experiments-app/src/screens/TextInputEvents.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import * as React from 'react';
22
import { StyleSheet, SafeAreaView, TextInput } from 'react-native';
3-
import { buildEventLogger } from '../utils/helpers';
3+
import { buildEventLogger, logEvent } from '../utils/helpers';
44

55
const handlePressIn = buildEventLogger('pressIn');
66
const handlePressOut = buildEventLogger('pressOut');
77
const handleFocus = buildEventLogger('focus');
88
const handleBlur = buildEventLogger('blur');
99
const handleChange = buildEventLogger('change');
1010
const handleSubmitEditing = buildEventLogger('submitEditing');
11+
const handleKeyPress = buildEventLogger('keyPress');
12+
const handleTextInput = buildEventLogger('textInput');
13+
const handleSelectionChange = buildEventLogger('selectionChange');
1114

1215
export function TextInputEvents() {
1316
const [value, setValue] = React.useState('');
1417

1518
const handleChangeText = (value: string) => {
1619
setValue(value);
17-
console.log(`Event: changeText`, value);
20+
logEvent('changeText', value);
1821
};
1922

2023
return (
@@ -30,6 +33,9 @@ export function TextInputEvents() {
3033
onBlur={handleBlur}
3134
onChange={handleChange}
3235
onSubmitEditing={handleSubmitEditing}
36+
onSelectionChange={handleSelectionChange}
37+
onKeyPress={handleKeyPress}
38+
onTextInput={handleTextInput}
3339
/>
3440
</SafeAreaView>
3541
);

experiments-app/src/utils/helpers.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,19 @@ import { NativeSyntheticEvent } from 'react-native/types';
22

33
export function buildEventLogger(name: string) {
44
return (event: NativeSyntheticEvent<unknown>) => {
5-
const eventData = event?.nativeEvent ?? event;
6-
console.log(`Event: ${name}`, eventData);
5+
const payload = event?.nativeEvent ?? event;
6+
logEvent(name, payload);
77
};
88
}
9+
10+
export function logEvent(name: string, payload: unknown) {
11+
console.log(`Event: ${name}`, payload);
12+
13+
queueMicrotask(() => {
14+
console.log(` - ${name} (microtask)`);
15+
});
16+
17+
setTimeout(() => {
18+
console.log(` - ${name} (macrotask)`);
19+
}, 0);
20+
}

0 commit comments

Comments
 (0)