Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-04 Thread Rafael Weinstein
If you wish, you can maintain a WeakMap of observed objects. If you wish to never process a changeRecord for an object you've stopped observing, you can simply check the WeakMap to see if it's still observed. On Fri, Nov 2, 2012 at 9:50 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote:

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-04 Thread Yehuda Katz
In my experience, it is very common to want to process changeRecords that were created, even if you letter turned off the observer. Turning off observers (in particular, temporarily), can be useful for avoiding certain kinds of cycles when creating bidrectional links. On Sat, Nov 3, 2012 at

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Rafael Weinstein
Andrea, I believe the example is correct. The way the API works is this: Object.observe and Object.unobserve both *synchronously* register/unregister your callback as observing/unobserving any given object. The asynchrony has to do with having changeRecords delivered -- that happens

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Andrea Giammarchi
hey, thanks for coming back. The asynchronous unobserve in the meaning that Object.unobserve is performed synchronously but the delivery of records is asynchronous and performed regardless the object is not observed anymore. Inside the observer each record can point to an object that is no more

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Rafael Weinstein
Take for example: function myCallback(recs) { console.log(recs.length); } var obj = {}; Object.observe(obj, myCallback); obj.a = 1; // enqueues changeRecord obj.b = 2; // enqueues changeRecord Object.unobserve(obj, myCallback); obj.c = 3; // does not enqueue changeRecord In the above

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Andrea Giammarchi
Main reason to use observe, in my opinion, is the ability to react on changes. The moment an observer implements this reacting logic there's no way it can work as expected if the object, or one of them, in the list of records, is not observed anymore. Let's say the object is not observed because

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Erik Arvidsson
On Fri, Nov 2, 2012 at 12:22 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: How to make this simple ... if I switch off the TV I don't expect any eco after ... I don't care about the program, it should not bother me. If you stick to the TV analogy... You don't want Tivo to erase what

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-02 Thread Andrea Giammarchi
fair enough, but I want to know what I am seeing is recorded and the TV is switched off ... how? Flagging records? Flagging objects? Via getNotifier ? On Fri, Nov 2, 2012 at 11:56 AM, Erik Arvidsson erik.arvids...@gmail.comwrote: On Fri, Nov 2, 2012 at 12:22 PM, Andrea Giammarchi

Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-01 Thread Andrea Giammarchi
Just wondering if this is actually meant/expected, I am talking about the example here: http://wiki.ecmascript.org/doku.php?id=harmony:observe#example and the fact it should show something in console while in my opinion that should show nothing since the Object.unobserve is called in the same

Re: Synchronous Object.observe but Asynchronous Object.unobserve ?

2012-11-01 Thread Erik Arvidsson
On Thu, Nov 1, 2012 at 4:32 PM, Andrea Giammarchi andrea.giammar...@gmail.com wrote: Just wondering if this is actually meant/expected, I am talking about the example here: http://wiki.ecmascript.org/doku.php?id=harmony:observe#example I'm not sure I understand your point. The example is not