Code Monkey home page Code Monkey logo

Comments (2)

alxhub avatar alxhub commented on May 8, 2024

Your example is attempting to update list mutably, but the custom equality function doesn't handle mutable updates.

this.list.update((list) => {
      list.push('a');
      return list;
    });

This call to update returns the same instance of the array (after pushing a new item). This will call the custom equality function with the same instance of the array as arr1 and arr2. Since the implementation compares arr1.length === arr2.length it will return true, which makes list assume nothing has changed (and not propagate a notification).

from angular.

rearl avatar rearl commented on May 8, 2024

@alxhub thanks for your reply and explanation, which makes totally sense (embarrassing I didn't see that myself).
As a consequence, we must always provide a new instance for set() and update() for signals. After realising the issue, it is clear to me. Nevertheless, I think it would be helpful to add this to the Signal guide - it should be especially mentioned in the section Signal equality functions which was misleading me (I see that the example is to show that two different instances with the same content should be considered equal).

from angular.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.