You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Experiment: Infer the current event priority from the native event (facebook#20748)
* Add the feature flag
* Add a host config method
* Wire it up to the work loop
* Export constants for third-party renderers
* Document for third-party renderers
Copy file name to clipboardExpand all lines: packages/react-reconciler/README.md
+26Lines changed: 26 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,32 @@ You can proxy this to `queueMicrotask` or its equivalent in your environment.
211
211
212
212
This is a property (not a function) that should be set to `true` if your renderer is the main one on the page. For example, if you're writing a renderer for the Terminal, it makes sense to set it to `true`, but if your renderer is used *on top of* React DOM or some other existing renderer, set it to `false`.
213
213
214
+
#### `getCurrentEventPriority`
215
+
216
+
To implement this method, you'll need some constants available on the _returned_`Renderer` object:
217
+
218
+
```js
219
+
constHostConfig= {
220
+
// ...
221
+
getCurrentEventPriority() {
222
+
returnMyRenderer.DefaultEventPriority;
223
+
},
224
+
// ...
225
+
}
226
+
227
+
constMyRenderer=Reconciler(HostConfig);
228
+
```
229
+
230
+
The constant you return depends on which event, if any, is being handled right now. (In the browser, you can check this using `window.event && window.event.type`).
231
+
232
+
***Discrete events:** If the active event is _directly caused by the user_ (such as mouse and keyboard events) and _each event in a sequence is intentional_ (e.g. `click`), return `MyRenderer.DiscreteEventPriority`. This tells React that they should interrupt any background work and cannot be batched across time.
233
+
234
+
***Continuous events:** If the active event is _directly caused by the user_ but _the user can't distinguish between individual events in a sequence_ (e.g. `mouseover`), return `MyRenderer.ContinuousEventPriority`. This tells React they should interrupt any background work but can be batched across time.
235
+
236
+
***Other events / No active event:** In all other cases, return `MyRenderer.DefaultEventPriority`. This tells React that this event is considered background work, and interactive events will be prioritized over it.
237
+
238
+
You can consult the `getCurrentEventPriority()` implementation in `ReactDOMHostConfig.js` for a reference implementation.
239
+
214
240
### Mutation Methods
215
241
216
242
If you're using React in mutation mode (you probably do), you'll need to implement a few more methods.
0 commit comments