Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

collection watches are not working #31

Description

@tbosch

Watching a collection that is stored in a property of an object does not work.
I found the problem, see 9417cd4

The change should be fine, as the line is in the Angular.dart code and was just missing. Could you add unit tests for this?

Activity

  1. caitp commented on May 6, 2014

    @caitp
    Contributor

    So I was investigating this yesterday and over the weekend, and what I'm finding is that CollectionAST(FieldReadAST(ContextReferenceAST)) works well, but FieldReadAST(ContextReferenceAST) doesn't (because a CollectionAST handler never does anything).

    So, this is the issue we have with a dynamic language like javascript -- we don't know in advance that a particular field must contain a List (or something), it might initially be undefined, and then turn into a list, and then turn into a string, or whatever.

    Because of this, there are only really 2 options, I think:

    1. something similar to $watchCollection which will make sure to set up the CollectionAST node, even if the value isn't a collection at the time of parsing

    2. totally scrap the strategy based on a more statically typed language, and do something more dynamic --- let a particular field's handlers change at runtime, and support reporting change between non-collection to collection and vice versa.

    I think option 2) could hurt performance a fair bit, but I don't really have a measure of the performance cost.

    However, neither of the situations I mentioned have anything to do with 9417cd4 as far as I can tell, so you may be reproducing the issue differently. Can you show a test case?

  2. tbosch commented on May 6, 2014

    @tbosch
    ContributorAuthor

    Hi,
    the problem is when the collection reference changes. Here is a test (to be put into watchgroups.spec.js):

      describe('collections', function() {
        iit('should watch collections if their reference changes', ()=>{
          setup({'a': [1]});
          var ast = new CollectionAST(new FieldReadAST(new ContextReferenceAST(), 'a'));
          var watch = watchGrp.watch(ast, logCurrentValue);
          watchGrp.detectChanges();
          logger.clear();
    
          context.a = [2];
          watchGrp.detectChanges();
          expect(logger._list[0].iterable).toEqual([2]);
        });
      });
    
  3. caitp commented on May 9, 2014

    @caitp
    Contributor

    @mhevery what was the strategy in Dart for handling this? The problem is that the DirtyCheckingRecord with the CollectionHandler is the first thing which is dirty checked, so its internal copy of the array still references the old array (because the FieldRead handler hasn't done its work yet)

    There are lots of ways around this, but I want to make sure it's in sync with the dart implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions