Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Infinite loop on pushing to array #67

Open

Description

@gdude2002

I'm using Node.JS version 0.10.26 with Watch.JS stored locally instead of using NPM (as the NPM version doesn't work).

When I push to an array within an object, Watch.JS seems to get stuck in an infinite loop.

var watchjs = require("./app/utils/watch"), // watchjs.watch(obj, function (prop, action, difference, oldvalue), <int> levels, true);
    obj = {"objectpacks": {"model_ids": ["ABCD"]}};

function watch(prop, action, difference, oldvalue) {
    watchjs.noMore = true;

    console.log("WATCH | Prop:", prop);
    console.log("WATCH | Action:", action);
    console.log("WATCH | Difference:", difference);
    console.log("WATCH | Oldvalue:", oldvalue);
}

watchjs.watch(obj, watch, 10, true);


function test() {
    console.log("Pushing.");
    obj.objectpacks.model_ids.push("test");
}

setTimeout(test, 2000);

Results in the following output..

Pushing.
WATCH | Prop: model_ids
WATCH | Action: push
WATCH | Difference: { '0': 'test' }
WATCH | Oldvalue: undefined
WATCH | Prop: objectpacks
WATCH | Action: differentattr
WATCH | Difference: { added: [ 'ABCD,test' ], removed: [] }
WATCH | Oldvalue: { model_ids: [ [Getter/Setter], 'test' ] }
WATCH | Prop: objectpacks
WATCH | Action: differentattr
WATCH | Difference: { added: [ 'ABCD,test' ], removed: [ 'ABCD,test' ] }
WATCH | Oldvalue: { model_ids: [ [Getter/Setter], 'test' ],
  'ABCD,test': undefined }
WATCH | Prop: objectpacks
WATCH | Action: differentattr
WATCH | Difference: { added: [ 'ABCD,test' ], removed: [ 'ABCD,test' ] }
WATCH | Oldvalue: { model_ids: [ [Getter/Setter], 'test' ],
  'ABCD,test': undefined }
WATCH | Prop: objectpacks
WATCH | Action: differentattr
WATCH | Difference: { added: [ 'ABCD,test' ], removed: [ 'ABCD,test' ] }
WATCH | Oldvalue: { model_ids: [ [Getter/Setter], 'test' ],
  'ABCD,test': undefined }

This loops until it's killed.
Any ideas?

Activity

  1. gdude2002 commented on Mar 5, 2014

    @gdude2002
    Author

    Removing the 10 from the function here does solve the problem, but why?

  2. rcleozier commented on Sep 15, 2014

    @rcleozier

    Bump... Having the same exact issue

  3. seawolff commented on Oct 28, 2014

    @seawolff

    Same issue here, even unwatching after first iteration causes a complete crash. In Chrome 38 in case it's useful.

  4. gdude2002 commented on Oct 28, 2014

    @gdude2002
    Author

    I'm not hopeful that the dev will respond here, but please remember to post your code, @rcleozier and @seawolff

  5. seawolff commented on Oct 29, 2014

    @seawolff

    @gdude2002 Here is my code. It's abbreviated and in CoffeeScript though:

    class Validation
      errors: []
      constructor: (data) ->
        # More code ...
        @errors.push {code: data.errors.error.code, message: data.errors.error.message}
    
    class Billing_Form
      constructor: () ->
        # data = data returned from ajax
        validation = new Validation(data)
        watch validation, "errors", callback = ->
          console.log validation.errors
          unwatch validation, "errors", callback #even with unwatch it will loop forever
          return 
    

    However to reproduce simply watch a bound array on an object and push data into it.

  6. melanke commented on Oct 31, 2014

    @melanke
    Owner

    Sorry guys, anything I can help you with? I am not currently working on Watch. Sorry about that, but any pull request will be appreciated

  7. seawolff commented on Nov 13, 2014

    @seawolff

    @melanke yeah, same. I'll get a PR open ASAP

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions