Files
JKVideo/store/miniExclusion.ts
Developer 53c67079a1 bug修改
2026-05-12 20:27:30 +08:00

31 lines
958 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* MiniPlayer ↔ LiveMiniPlayer 互斥协调。
* 通过 zustand subscribe 在外部串联两个 store避免它们直接互相 import
* 造成循环依赖(曾导致 Metro / TS 编译时内存暴涨)。
*
* 仅需在 app 启动时 import 一次_layout.tsx即可生效。
*/
import { useVideoStore } from './videoStore';
import { useLiveStore } from './liveStore';
let initialized = false;
export function initMiniExclusion() {
if (initialized) return;
initialized = true;
// 视频 mini 激活 → 清掉直播 mini
useVideoStore.subscribe((state, prev) => {
if (state.isActive && !prev.isActive && useLiveStore.getState().isActive) {
useLiveStore.getState().clearLive();
}
});
// 直播 mini 激活 → 清掉视频 mini
useLiveStore.subscribe((state, prev) => {
if (state.isActive && !prev.isActive && useVideoStore.getState().isActive) {
useVideoStore.getState().clearVideo();
}
});
}