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
useBlockRefs: use more efficient lookup map, use uSES (#60945)
* useBlockRefs: use more efficient lookup map, use uSES
* Rewrite block refs with observableMap, which moves to compose
* Improve docs
* Add changelog entry
Copy file name to clipboardexpand all lines: packages/compose/CHANGELOG.md
+2
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
## Unreleased
4
4
5
+
- Added new `observableMap` data structure and `useObservableValue` React hook ([#60945](https://github.com/WordPress/gutenberg/pull/60945)).
Copy file name to clipboardexpand all lines: packages/compose/README.md
+21
Original file line number
Diff line number
Diff line change
@@ -129,6 +129,14 @@ _Returns_
129
129
130
130
- Higher-order component.
131
131
132
+
### observableMap
133
+
134
+
A constructor (factory) for `ObservableMap`, a map-like key/value data structure where the individual entries are observable: using the `subscribe` method, you can subscribe to updates for a particular keys. Each subscriber always observes one specific key and is not notified about any unrelated changes (for different keys) in the `ObservableMap`.
135
+
136
+
_Returns_
137
+
138
+
-`ObservableMap< K, V >`: A new instance of the `ObservableMap` type.
139
+
132
140
### pipe
133
141
134
142
Composes multiple higher-order components into a single higher-order component. Performs left-to-right function composition, where each successive invocation is supplied the return value of the previous.
@@ -442,6 +450,19 @@ _Returns_
442
450
443
451
-`import('react').RefCallback<TypeFromRef<TRef>>`: The merged ref callback.
444
452
453
+
### useObservableValue
454
+
455
+
React hook that lets you observe an entry in an `ObservableMap`. The hook returns the current value corresponding to the key, or `undefined` when there is no value stored. It also observes changes to the value and triggers an update of the calling component in case the value changes.
456
+
457
+
_Parameters_
458
+
459
+
-_map_`ObservableMap< K, V >`: The `ObservableMap` to observe.
460
+
-_name_`K`: The map key to observe.
461
+
462
+
_Returns_
463
+
464
+
-`V | undefined`: The value corresponding to the map key requested.
465
+
445
466
### usePrevious
446
467
447
468
Use something's value from the previous render. Based on <https://usehooks.com/usePrevious/>.
0 commit comments