Open bllanos opened 9 years ago
There are a few problems with object.observe (v0.2.4) and observe-js (v0.4.2). The main issue with both libraries is that they do not guarantee that they report operations in the order they occurred. This means that some operations can even not be reported at all (if a delete was reported before a change or add, for example). It seems there is nothing that can be done about this in a Javascript polyfill. While the native implementation of Object.observe seems to preserve order, the Node's Javascript runtime does not support it yet.
There are also some likely bugs with both libraries. The object.observe library seems to continue monitoring objects even when unobserved is called (thus never terminating the script). The objserve-js library seem to have an issue where, if any property of an object that is being observed contains the value 'NaN', then it will over-report on the variable even when it doesn't change.
@bllanos and I have decided that this issue can remain for now. This documentation was provided to aid me or future developers attempting to fix the issue of addition and deletion monitoring.
For future reference, added properties should not have their accesses checked, as it is possible for them to be accessed before the wrapper code receives notification of their existence (and has a chance to wrap them in getter/setter functions).
This should be mentioned in the documentation of the project.
Current behaviour
src/wrapper/wrapper.coffee
) have accessor properties corresponding to each own property of the source object at the time of their creation.Possible solutions
The idea solution would be to use
Object.observe()
, which is part of ECMAScript 7 and not yet available in all environments.In the meantime, there are many polyfills and full-blown libraries that approximate
Object.observe()
. After searching the NPM website for "object.observe" and "observe", I have a few favourites so far:observe-js
seems to be quite popular, and will work withoutObject.observe
.observe-plus
, can recursively observe objects (Object.observe
only observes the top-level properties of an object).Object.observe
already exists.object.observe
is a straight-forward polyfill.Note that polyfills perform "dirty checking", which is expensive and can be easily misused to cause memory leaks.
Details and Validation
Object.defineProperty()
are recorded. (Such changes bypass the current wrapper code.)OBSERVATION_CATEGORIES
) insrc/util/constants.coffee
Resources
Object.observe
at HTML 5 RocksObject.observe