苗条,只重新渲染列表中的项目,而不是整个列表

时间:2020-04-16 17:38:10

标签: javascript svelte svelte-3 svelte-component urql

同时具有svelte-apollohttps://github.com/timhall/svelte-apollo/issues/19)和@urql-sveltehttps://github.com/FormidableLabs/urql/issues/704),我要重新渲染整个列表,而不仅仅是元素要重新渲染。 / p>

复制步骤:

如果我在这里阅读: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是最后一个新数组吗?

0 个答案:

没有答案
相关问题