[Persisted] Make broadcast subscriptions granular by key (#4874)

* Add fast path for guaranteed noop updates

* Change persisted.onUpdate() API to take a key

* Implement granular broadcast listeners
This commit is contained in:
dan
2024-08-06 01:30:52 +01:00
committed by GitHub
parent 966f6c511f
commit 686d5ebb53
17 changed files with 95 additions and 42 deletions
+3 -2
View File
@@ -1,4 +1,5 @@
import React from 'react'
import * as persisted from '#/state/persisted'
type StateContext = persisted.Schema['invites']
@@ -35,8 +36,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
)
React.useEffect(() => {
return persisted.onUpdate(() => {
setState(persisted.get('invites'))
return persisted.onUpdate('invites', nextInvites => {
setState(nextInvites)
})
}, [setState])