Skip to content

Commit

Permalink
fix(store): singleton store guard
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Oct 27, 2024
1 parent eb01d03 commit 5a8725b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const EntryItemWrapper: FC<
[entry.entries.url],
)
const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown(() => setIsContextMenuOpen(false))
useAnyPointDown(() => isContextMenuOpen && setIsContextMenuOpen(false))
const handleContextMenu: React.MouseEventHandler<HTMLDivElement> = useCallback(
(e) => {
e.preventDefault()
Expand Down
2 changes: 1 addition & 1 deletion apps/renderer/src/modules/feed-column/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function FeedCategoryImpl({ data: ids, view, categoryOpenStateData }: FeedCatego

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown(() => {
setIsContextMenuOpen(false)
isContextMenuOpen && setIsContextMenuOpen(false)
})
const isCategoryIsWaiting = isChangePending

Expand Down
6 changes: 3 additions & 3 deletions apps/renderer/src/modules/feed-column/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const FeedItemImpl = ({ view, feedId, className }: FeedItemProps) => {

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown(() => {
setIsContextMenuOpen(false)
isContextMenuOpen && setIsContextMenuOpen(false)
})
if (!feed) return null

Expand Down Expand Up @@ -208,7 +208,7 @@ const ListItemImpl: Component<{

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown(() => {
setIsContextMenuOpen(false)
isContextMenuOpen && setIsContextMenuOpen(false)
})
const subscription = useSubscriptionByFeedId(listId)
const navigate = useNavigateEntry()
Expand Down Expand Up @@ -291,7 +291,7 @@ const InboxItemImpl: Component<{

const [isContextMenuOpen, setIsContextMenuOpen] = useState(false)
useAnyPointDown(() => {
setIsContextMenuOpen(false)
isContextMenuOpen && setIsContextMenuOpen(false)
})
const navigate = useNavigateEntry()
const handleNavigate = useCallback(
Expand Down
7 changes: 7 additions & 0 deletions apps/renderer/src/store/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const storeMap = {} as Record<string, UseBoundStoreWithEqualityFn<any>>
export const createZustandStore =
<S, T extends StateCreator<S, [], []> = StateCreator<S, [], []>>(name: string) =>
(store: T) => {
if (import.meta.env.DEV && window[`store_${name}`]) {
import.meta.hot?.send("message", "The store has been changed, reloading...")
globalThis.location.reload()
}

const newStore = import.meta.env.DEV
? createWithEqualityFn(
devtools(store, {
Expand All @@ -60,6 +65,8 @@ export const createZustandStore =
},
)

window[`store_${name}`] = newStore

return newStore
}
type FunctionKeys<T> = {
Expand Down
5 changes: 5 additions & 0 deletions plugins/vite/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ function isNodeWithinCircularImports(

export const circularImportRefreshPlugin = (): Plugin => ({
name: "circular-import-refresh",
configureServer(server) {
server.ws.on("message", (message) => {
console.info(message)
})
},
handleHotUpdate({ file, server }: HmrContext) {
const mod = server.moduleGraph.getModuleById(file)

Expand Down

0 comments on commit 5a8725b

Please sign in to comment.