melanke / Watch.JS

watch the changes of any object or attribute
Other
2.14k stars 219 forks source link

Maximum call stack size exceeded #105

Closed bloodcarter closed 7 years ago

bloodcarter commented 7 years ago

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);  
xwisdom commented 7 years ago

Do you have a working example that generates this error?

bloodcarter commented 7 years ago

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;
melanke commented 7 years ago

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;
bloodcarter commented 7 years ago

@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?