fix lost events when yielding (#1521)

This commit is contained in:
Thomas Brandého 2023-08-05 01:39:46 +02:00 committed by GitHub
parent a9b7394e0e
commit 134df9dbaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,25 +49,29 @@ export default function Component() {
processEvent({{state_name}}, {{state_name|react_setter}}, {{const.result}}, {{const.result|react_setter}}, {{const.router}}, {{const.socket}}.current) processEvent({{state_name}}, {{state_name|react_setter}}, {{const.result}}, {{const.result|react_setter}}, {{const.router}}, {{const.socket}}.current)
} }
// Reset the result.
{{const.result|react_setter}}(result => {
// If there is a new result, update the state. // If there is a new result, update the state.
if ({{const.result}}.{{const.state}} != null) { if ({{const.result}}.{{const.state}} != null) {
// Apply the new result to the state and the new events to the queue. // Apply the new result to the state and the new events to the queue.
{{state_name|react_setter}}(state => ({ {{state_name|react_setter}}(state => {
return {
...{{const.result}}.{{const.state}}, ...{{const.result}}.{{const.state}},
events: [...state.{{const.events}}, ...{{const.result}}.{{const.events}}], events: [...state.{{const.events}}, ...{{const.result}}.{{const.events}}],
})) }
})
// Reset the result. return {
{{const.result|react_setter}}(result => ({
{{const.state}}: null, {{const.state}}: null,
{{const.events}}: [], {{const.events}}: [],
{{const.final}}: true, {{const.final}}: true,
{{const.processing}}: !{{const.result}}.{{const.final}}, {{const.processing}}: !{{const.result}}.{{const.final}},
})) }
}
return result;
})
// Process the next event. // Process the next event.
processEvent({{state_name}}, {{state_name|react_setter}}, {{const.result}}, {{const.result|react_setter}}, {{const.router}}, {{const.socket}}.current) processEvent({{state_name}}, {{state_name|react_setter}}, {{const.result}}, {{const.result|react_setter}}, {{const.router}}, {{const.socket}}.current)
}
}) })
// Set focus to the specified element. // Set focus to the specified element.