melanke / Watch.JS

watch the changes of any object or attribute

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maximum call stack size exceeded

bloodcarter opened this issue · comments

  1. When not specifying level and set new objects = true got Maximum call stack size exceeded.
  2. If doing this, no changes catch at all:
watch(this, function(prop, action, newvalue, oldvalue){
        //logger.error('%s has changed', prop);
       // WatchJS.noMore = true;
        logger.error("%j - action: %j - new: %j, old: %j... and the context: %j", prop, action, newvalue, oldvalue,this);
    }, 2, false);  

Do you have a working example that generates this error?

This, for instance

'use strict';

var logger = require("./logger");

var WatchJS = require("watchjs")
var watch = WatchJS.watch;
var unwatch = WatchJS.unwatch;
var callWatchers = WatchJS.callWatchers;

var x = 0;

watch(x, function(prop, action, newvalue, oldvalue){
        //logger.error('%s has changed', prop);
       // WatchJS.noMore = true;
        console.log("trigger!");
    }, 2, false);  

x = 2;

x must have a parent object:

var parent = { x: 0};

watch(parent, "x", function(prop, action, newvalue, oldvalue){
        //logger.error('%s has changed', prop);
       // WatchJS.noMore = true;
        console.log("trigger!");
    }, 2, false);  

parent.x = 2;

@melanke Does that mean that I cannot pass this to the watch function? What should I do in order to use it inside an object?