refactor: state 管理优化 - 结构化浅比较 + update/setIn/batch API

- state.js: 新增 shallowEqual、update()、setIn()、batch() 方法
- input-area.js: messages.push() 全部改为 state.update(),确保引用变化触发通知
- model-bar.js: 直接属性赋值改为 state.update(),修复 model 切换不触发变更检测
This commit is contained in:
thzxx
2026-04-05 01:27:24 +08:00
parent e519631bee
commit b802c896cf
3 changed files with 177 additions and 29 deletions
+1 -2
View File
@@ -24,8 +24,7 @@ export function initModelBar() {
const model = modelSelectEl.value;
if (db()) await db().saveSetting('selectedModel', model);
state.set('_defaultModel', model);
const session = state.get(KEYS.CURRENT_SESSION);
if (session) session.model = model;
state.update(KEYS.CURRENT_SESSION, session => session ? ({ ...session, model }) : session);
if (model) {
await checkModelCapability(model);
} else {