Code Monkey home page Code Monkey logo

Comments (2)

alexthewilde avatar alexthewilde commented on September 23, 2024

+1

from angular-underscore.

aolieman avatar aolieman commented on September 23, 2024

The cause is that Angular's digest loop evaluates expressions at least twice, to check if their output is stable. It clearly isn't in the case of shuffle, but other functions with non-deterministic return values, e.g. pairs(), will also cause Angular to get stuck.

The simple solution is to move any expressions with (intermediate, in the case of filters,) non-deterministic return values to your controller (i.e. out of the template). The workaround for this module that comes to mind is to sort the output of non-deterministic functions that are especially useful in templates (such as pairs()). It incurs a bit of overhead, and will be a less clean mapping to underscore, but it will make this module more usable. Currently, I end up shadowing sorted versions of these functions in my controllers.

It would be nice if Angular could take the entire expression into account (i.e. plus filters), so that this issue would not be caused by expressions that sort their output with filters. Perhaps someone would like to upstream this issue there.

EDIT: the workaround isn't as simple as I stated above. For users of this module, ngRepeat's track by clause may help. A true solution will likely involved modified $watch calls.

from angular-underscore.

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.