Code Monkey home page Code Monkey logo

Comments (11)

pasky avatar pasky commented on June 12, 2024 4

This is one of the top google results for Aurelia not reacting to array element changes. In my view, it's no big deal if Aurelia doesn't support this implicitly, but it'd be great to mention a precise recipe to work the issue around and force the update manually. For example, I have found the suggestion to replace this.samples_loaded[i] = true; with this.samples_loaded.splice(i, 1, true); but that doesn't help...

from binding.

jdanyow avatar jdanyow commented on June 12, 2024 2

@GBreeze aurelia does not observe array mutation via indexed assignment (eg arr[x] = y) because it would require dirty-checking now that Object.observe is discontinued. Use splice instead:

if (!Array.prototype.swap) {
    Array.prototype.swap = function (newIndex: number, oldIndex: number) {
        const temp = this[newIndex];
        this.splice(newIndex, 1, this[oldIndex]);
        this.splice(oldIndex, 1, temp);
        return this;
    }
}

from binding.

davismj avatar davismj commented on June 12, 2024 1

What about employing dirty checking in these scenarios? Is there any way to
communicate to the developer at runtime that he shouldn't expect it to
work?
On Apr 7, 2015 10:27 PM, "Rob Eisenberg" [email protected] wrote:

We can't fix this. It's impossible with native Array.observe. It's the one
flaw in the binding system. The only way to get around it is to create a
helper method on array that would notify the changes and use that instead
of the indexer when you want to change something. You can always use splice
as well. But, JS provides no way to override the indexer (at least no way
that isn't insane and non-scalable).


Reply to this email directly or view it on GitHub
#64 (comment).

from binding.

MeirionHughes avatar MeirionHughes commented on June 12, 2024 1

Anyone having issues with this; check out this example: https://gist.run/?id=c3d618546a0fef10a266109465eed94c

by using splice and the property indexer (string) you can get the binding working - but I believe this is dirty checked.

from binding.

EisenbergEffect avatar EisenbergEffect commented on June 12, 2024

We can't fix this. It's impossible with native Array.observe. It's the one flaw in the binding system. The only way to get around it is to create a helper method on array that would notify the changes and use that instead of the indexer when you want to change something. You can always use splice as well. But, JS provides no way to override the indexer (at least no way that isn't insane and non-scalable).

from binding.

EisenbergEffect avatar EisenbergEffect commented on June 12, 2024

Basically, use dirty checking on array indexes...hmmm. That could work.

On Tue, Apr 7, 2015 at 11:18 PM, Matthew James Davis <
[email protected]> wrote:

What about employing dirty checking in these scenarios? Is there any way to
communicate to the developer at runtime that he shouldn't expect it to
work?
On Apr 7, 2015 10:27 PM, "Rob Eisenberg" [email protected] wrote:

We can't fix this. It's impossible with native Array.observe. It's the
one
flaw in the binding system. The only way to get around it is to create a
helper method on array that would notify the changes and use that instead
of the indexer when you want to change something. You can always use
splice
as well. But, JS provides no way to override the indexer (at least no way
that isn't insane and non-scalable).


Reply to this email directly or view it on GitHub
#64 (comment).


Reply to this email directly or view it on GitHub
#64 (comment).

Rob Eisenberg,
President - Blue Spire
www.durandaljs.com

from binding.

EisenbergEffect avatar EisenbergEffect commented on June 12, 2024

Not sure if we should do anything about this or not just yet.

from binding.

pfurini avatar pfurini commented on June 12, 2024

Does #76 covers an expression like data[0].property ?
It seems my binding doesn't get notified when property changes, even if it is defined as an ES property..

Forgot to mention that I have used Typescript inheritance in my view model, and that the data array is defined on the base class and not on the viewmodel that is used by the view. It can be an issue?

from binding.

EisenbergEffect avatar EisenbergEffect commented on June 12, 2024

@jdanyow Since you are working on the binding docs currently, can you be sure to include this information and recommendation in that. (Along with any other common scenarios you've seen over the last months.)

from binding.

MeirionHughes avatar MeirionHughes commented on June 12, 2024

taking suggestions on how/when to warn about this issue: https://github.com/MeirionHughes/aurelia-template-lint/issues/82#issuecomment-250273617

from binding.

gp-slick-coder avatar gp-slick-coder commented on June 12, 2024

What is with polyfills, is there a workaround?

Example:

if (!Array.prototype.swap) {
    Array.prototype.swap = function (newIndex: number, oldIndex: number) {
        let temp = this[newIndex];
        this[newIndex] = this[oldIndex];
        this[oldIndex] = temp;
        return this
    }
}

this does not reflect on a 'repeat.for' binding :-|

from binding.

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.