mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
🐛 fix(gtd): fix frozen object mutation in updateTodos (#11184)
* 🐛 fix(gtd): add console.log for updateTodos debugging * 🐛 fix(gtd): fix frozen object mutation in updateTodos * 🐛 fix(gtd): remove debug console.log
This commit is contained in:
@@ -151,13 +151,15 @@ class GTDExecutor extends BaseExecutor<typeof GTDApiNameEnum> {
|
||||
}
|
||||
case 'update': {
|
||||
if (op.index !== undefined && op.index >= 0 && op.index < updatedTodos.length) {
|
||||
const item = updatedTodos[op.index];
|
||||
// Create a new object to avoid mutating frozen/immutable objects from store
|
||||
const updatedItem = { ...updatedTodos[op.index] };
|
||||
if (op.newText !== undefined) {
|
||||
item.text = op.newText;
|
||||
updatedItem.text = op.newText;
|
||||
}
|
||||
if (op.completed !== undefined) {
|
||||
item.completed = op.completed;
|
||||
updatedItem.completed = op.completed;
|
||||
}
|
||||
updatedTodos[op.index] = updatedItem;
|
||||
results.push(`Updated item ${op.index + 1}`);
|
||||
}
|
||||
break;
|
||||
@@ -171,7 +173,8 @@ class GTDExecutor extends BaseExecutor<typeof GTDApiNameEnum> {
|
||||
}
|
||||
case 'complete': {
|
||||
if (op.index !== undefined && op.index >= 0 && op.index < updatedTodos.length) {
|
||||
updatedTodos[op.index].completed = true;
|
||||
// Create a new object to avoid mutating frozen/immutable objects from store
|
||||
updatedTodos[op.index] = { ...updatedTodos[op.index], completed: true };
|
||||
results.push(`Completed: "${updatedTodos[op.index].text}"`);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user