Repository navigation
优化ReduxStore与广播机制 - #729
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR optimizes the Redux Store and broadcast mechanism for script management. It removes Redux Store usage from script lists in favor of event-based updates to prevent unnecessary caching and improves batch operations handling.
- Replaces Redux Store with direct state management and event subscription for better memory management
- Implements batch operations for delete, enable, and sort operations to reduce message traffic
- Optimizes event message data size by removing unnecessary information
Reviewed Changes
Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/store/utils.ts | Converts loadScriptFavicons to async generator for batch processing |
| src/pages/store/subscribe.ts | Removes Redux Store subscription handlers |
| src/pages/store/store.ts | Removes script slice from Redux Store |
| src/pages/store/features/script.ts | Converts Redux actions to plain async functions |
| src/pages/options/routes/ScriptList.tsx | Replaces Redux Store with local state and event subscriptions |
| src/pages/options/main.tsx | Removes store subscription initialization |
| src/pages/install/App.tsx | Fixes variable naming conflict and URL parameter parsing |
| src/pages/confirm/App.tsx | Improves URL parameter parsing with URLSearchParams |
| src/pages/popup/App.tsx | Removes CSS transform, adds flex layout for menu items |
| src/app/service/service_worker/script.ts | Implements batch operations for scripts (delete, enable, sort) |
| src/app/service/queue.ts | Updates message types for batch operations |
|
使用Redux Store也是一次尝试,至少我觉得他将数据、操作和组件抽离开来这块是有意义的 现在这样的话,我觉得可以考虑封装一个 useScriptlist 的 hook,不然全塞一个组件里面,似乎不是很合适,而且看起来很乱,就比如,每个地方都要写上:updateScriptListMultiple,如此的话,把Redux Store删掉我也是赞成的 |
React的Redux用在单一页面跑SPA是很有用 |
|
9596f07 |
updateScriptListMultiple 那个是为了你的 enableLoading 和 actionLoading 这样的写法很清楚。前跟後 先合併這個。再另外提交改善 |
现在ScriptList是用Redux Store
但根本不需要。因为打开那一刻取一下,之后用事件机制就能进行更新
使用Redux Store的话,即使关掉页面也不会释放资讯
这是没必要的Cache
另外,事件机制的设计,未考虑批次删除,批次启用,批次禁用等处理
现在都改成批次事件
减少大量事件讯息传来传去
而且也改善了 事件讯息的资讯量。把不用的资讯量除去。
另外,修了删除跟新增时,其他script列表页面没更新sort的问题
改善后的机制:
在三个Tab打开了同一Script列表页
其中一个把部份Script删除 -> 发指示【执行批次删除】到 ServiceWorker -> ServiceWorker 处理 -> 广播【批次删除发生】
三个Tab同时收到广播【批次删除发生】,然后更新页面
其他代码优化
1)
window.location.search.split("=")[1];->new URLSearchParams(location.search).get("uuid");2) upsertScript -> mUpsertScript ( 避免變數名和function名一樣)
3)
transform: "translateY(1px)",-> flex 排版