-
Notifications
You must be signed in to change notification settings - Fork 96
feat(zero): offline #4652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(zero): offline #4652
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c0d5884
feat: added offline to zbugs and useZeroOffline
0xcadams fba0b98
Merge remote-tracking branch 'origin/main' into 0xcadams/offline
0xcadams 31ebf29
Merge branch 'main' into 0xcadams/offline
0xcadams 6d5be78
fix: updated with solidjs and feedback
0xcadams 096205b
chore: lint
0xcadams 1791569
Merge branch 'main' into 0xcadams/offline
0xcadams cb1534f
fix: reworked design
0xcadams 7c1401b
Merge remote-tracking branch '0xcadams/0xcadams/offline' into 0xcadam…
0xcadams f8f7fd3
fix: format
0xcadams a821ab2
Merge branch 'main' into 0xcadams/offline
0xcadams 06f1f5d
Merge branch 'main' into 0xcadams/offline
0xcadams dd11919
revert: revert changes to zbugs for follow-up
0xcadams 5bce8c9
test: added tests
0xcadams 10404b6
Revert "revert: revert changes to zbugs for follow-up"
0xcadams fb9fd9d
revert: zero init changes
0xcadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: updated with solidjs and feedback
- Loading branch information
commit 6d5be78e95cc6eb38772d505e9b1329d77b299cf
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {createSignal, onCleanup, type Accessor} from 'solid-js'; | ||
import {useZero} from './use-zero.ts'; | ||
|
||
/** | ||
* Tracks the online status of the current Zero instance. | ||
* | ||
* @returns An accessor — call `online()` to get a reactive `boolean`. | ||
* | ||
* @example | ||
* const online = useZeroOnline(); | ||
* | ||
* <span> | ||
* {online() ? 'Online' : 'Offline'} | ||
* </span> | ||
*/ | ||
export function useZeroOnline(): Accessor<boolean> { | ||
const zero = useZero()(); | ||
|
||
const [online, setOnline] = createSignal<boolean>(zero?.online ?? false); | ||
|
||
const unsubscribe = zero?.onOnline(setOnline); | ||
|
||
onCleanup(unsubscribe ?? (() => {})); | ||
|
||
return online; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nuts. @grgbkr had gone to a lot of trouble to pass in all the configuration to
Zero
. But I think didn't consider this problem/use-case. So maybe passing in all configuration cannot work.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can support both here. The adding/removal of listeners doesn't need to be all up-front. And this doesn't need to be deprecated.
Or, if it's better, we can move this all to the React/Solid layers. And continue to use
onOnlineChange
and track the online state with React Context.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be very convoluted to track the listeners state in the React/Solid layers. I'm ok with this change.
The other to event listener type configs we currently have are
onUpdateNeeded
andonClientStateNotFound
. Possibly these should move on to the Zero instance as well, and our general pattern would be event listeners on the Zero instance. I think these are unlikely to need multiple listeners like onOnline might, but it may just be more ergonomic to have them on Zero given React hooks. I think it would be good to build a UI foronUpdateNeeded
to figure out what is most ergonomic.