-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(runtime/external-store): rewrite sync mechanism (#630)
- Loading branch information
Showing
5 changed files
with
114 additions
and
154 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import { MessageStatus } from "../../types"; | ||
|
||
const AUTO_STATUS_RUNNING = Object.freeze({ type: "running" }); | ||
const AUTO_STATUS_COMPLETE = Object.freeze({ | ||
type: "complete", | ||
reason: "unknown", | ||
}); | ||
|
||
export const isAutoStatus = (status: MessageStatus) => | ||
status === AUTO_STATUS_RUNNING || status === AUTO_STATUS_COMPLETE; | ||
|
||
export const getAutoStatus = (isLast: boolean, isRunning: boolean) => | ||
isLast && isRunning ? AUTO_STATUS_RUNNING : AUTO_STATUS_COMPLETE; |
7 changes: 2 additions & 5 deletions
7
packages/react/src/runtimes/external-store/useExternalStoreRuntime.tsx
This file contains 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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
import { useEffect, useInsertionEffect, useState } from "react"; | ||
import { useInsertionEffect, useState } from "react"; | ||
import { ExternalStoreRuntime } from "./ExternalStoreRuntime"; | ||
import { ExternalStoreAdapter } from "./ExternalStoreAdapter"; | ||
|
||
export const useExternalStoreRuntime = (store: ExternalStoreAdapter<any>) => { | ||
export const useExternalStoreRuntime = <T,>(store: ExternalStoreAdapter<T>) => { | ||
const [runtime] = useState(() => new ExternalStoreRuntime(store)); | ||
|
||
useInsertionEffect(() => { | ||
runtime.store = store; | ||
}); | ||
useEffect(() => { | ||
runtime.onStoreUpdated(); | ||
}); | ||
|
||
return runtime; | ||
}; |
66 changes: 0 additions & 66 deletions
66
packages/react/src/runtimes/external-store/useExternalStoreSync.tsx
This file was deleted.
Oops, something went wrong.