mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] playground: fix crash in todo app example
This commit is contained in:
+14
-14
@@ -268,7 +268,7 @@ const TODO_APP_STORE = `// This example is an implementation of the TodoList app
|
|||||||
|
|
||||||
const ENTER_KEY = 13;
|
const ENTER_KEY = 13;
|
||||||
const ESC_KEY = 27;
|
const ESC_KEY = 27;
|
||||||
const LOCALSTORAGE_KEY = "todos-odoo";
|
const LOCALSTORAGE_KEY = "todomvc";
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Store Definition
|
// Store Definition
|
||||||
@@ -315,20 +315,20 @@ const actions = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function saveState(state) {
|
||||||
|
const str = JSON.stringify(state);
|
||||||
|
window.localStorage.setItem(LOCALSTORAGE_KEY, str);
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadState() {
|
||||||
|
const localState = window.localStorage.getItem(LOCALSTORAGE_KEY);
|
||||||
|
return localState ? JSON.parse(localState) : { todos: [], nextId: 1};
|
||||||
|
}
|
||||||
|
|
||||||
function makeStore() {
|
function makeStore() {
|
||||||
const todos = JSON.parse(
|
const state = loadState();
|
||||||
window.localStorage.getItem(LOCALSTORAGE_KEY) || "[]"
|
|
||||||
);
|
|
||||||
const nextId = Math.max(0, ...todos.map(t => t.id || 0)) + 1;
|
|
||||||
const state = {
|
|
||||||
todos,
|
|
||||||
nextId
|
|
||||||
};
|
|
||||||
const store = new owl.store.Store({ state, actions });
|
const store = new owl.store.Store({ state, actions });
|
||||||
store.on("update", null, () => {
|
store.on("update", null, () => saveState(store.state));
|
||||||
const state = JSON.stringify(store.state.todos);
|
|
||||||
window.localStorage.setItem(LOCALSTORAGE_KEY, state);
|
|
||||||
});
|
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +375,7 @@ class TodoItem extends owl.Component {
|
|||||||
if (!value) {
|
if (!value) {
|
||||||
this.removeTodo(this.props.id);
|
this.removeTodo(this.props.id);
|
||||||
} else {
|
} else {
|
||||||
this.env.dispatch("editTodo", {
|
this.env.store.dispatch("editTodo", {
|
||||||
id: this.props.id,
|
id: this.props.id,
|
||||||
title: value
|
title: value
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user