同时具有svelte-apollo
(https://github.com/timhall/svelte-apollo/issues/19)和@urql-svelte
(https://github.com/FormidableLabs/urql/issues/704),我要重新渲染整个列表,而不仅仅是元素要重新渲染。 / p>
转到REPL:https://codesandbox.io/s/urql-svelte-list-rerendering-uwsvn
单击一个按钮
每个按钮重新渲染;因此整个列表会重新呈现
我希望它只重新显示我单击的按钮
如果我在这里阅读:https://svelte.dev/tutorial/svelte-options,则可以通过使用以下内容来理解:
immutable = {true} —您从不使用可变数据,因此编译器可以执行简单的引用相等性检查来确定值是否已更改
immutable = {false}-默认值。 Svelte对于可变对象是否已更改将更加保守
如果您看到示例,它们将像我们对todos
所做的那样改变urql
数组:
let todos = [
{ id: 1, done: true, text: 'wash the car' },
{ id: 2, done: false, text: 'take the dog for a walk' },
{ id: 3, done: false, text: 'mow the lawn' }
];
function toggle(toggled) {
todos = todos.map(todo => {
if (todo === toggled) {
// return a new object
return {
id: todo.id,
text: todo.text,
done: !todo.done
};
}
// return the same object
return todo;
});
}
为什么我的REPL todos
示例不起作用?
todos
是最后一个新数组吗?