文件
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

55 行
1.6 KiB
TypeScript

import { produce, Draft } from 'immer';
import { defaultWindowId, stateUtils } from '../../reducer';
export const defaultState = {
watchedResources: {},
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Redux reducer composed across app-desktop/app-mobile with different state shapes; action types are heterogeneous
const reducer = produce((draft: Draft<any>, action: any) => {
if (action.type.indexOf('RESOURCE_EDIT_WATCHER_') !== 0) return;
try {
switch (action.type) {
case 'RESOURCE_EDIT_WATCHER_SET':
draft.watchedResources[action.id] = {
id: action.id,
title: action.title,
};
break;
case 'RESOURCE_EDIT_WATCHER_REMOVE':
// RESOURCE_EDIT_WATCHER_REMOVE signals that a resource is no longer being watched.
// As such, it should be removed from all windows' resource lists:
for (const windowId in draft.backgroundWindows) {
// watchedResources is per-window only on desktop:
if ('watchedResources' in draft.backgroundWindows[windowId]) {
delete draft.backgroundWindows[windowId].watchedResources[action.id];
}
}
delete draft.watchedResources[action.id];
break;
case 'RESOURCE_EDIT_WATCHER_CLEAR': {
const windowState = stateUtils.windowStateById(draft, action.windowId ?? defaultWindowId);
// The window may have already been closed.
const windowExists = !!windowState;
if (windowExists) {
windowState.watchedResources = {};
}
break;
}
}
} catch (error) {
error.message = `In plugin reducer: ${error.message} Action: ${JSON.stringify(action)}`;
throw error;
}
});
export default reducer;