MaxArt2501 / object-observe

Object.observe polyfill
MIT License
351 stars 30 forks source link

Object.observe polyfill

Object.observe polyfill based on EcmaScript 7 spec. Read the documentation for more detailed informations. Check the changelog to see what's changed.

For a polyfill for Array.observe, you can find something here.

Object.observe isn't a proposed spec anymore

You might have read this around, but back in November Object.observe proposal was withdrawn from TC39. This also means that Object.observe will be pulled from Chrome and other V8-based environments, and that would imply that developers shouldn't rely on it anymore. Web development evolved in the direction of functional programming and immutable objects, so that's where we all should look at.

You can find the discussion here. V8's development on Proxy objects is still going, though, as the proposal has been finalized for ES2015.

Regarding this polyfill, its development can be considered concluded. There is still a minor bug that allows to observe the global object, but I don't think I'll address it. In the meanwhile, this package (along with my polyfill for Array.observe) is now marked as deprecated on the npm registry.

For the future, I might extract the observing engine from this polyfill and serve it as project on its own, without the legacy of Object.observe interface. That could still be useful, especially for debugging purposes.

Installation

This polyfill extends the native Object and doesn't have any dependencies, so loading it is pretty straightforward:

<script src="https://github.com/MaxArt2501/object-observe/raw/master/object-observe.js"></script>

Using bower:

$ bower install object.observe

Or in node.js:

$ npm install object.observe

That's it. If the environment doesn't already support Object.observe, the shim is installed and ready to use.

For client side usage, if you only need the "light" version of the polyfill (see the documentation), replace object-observe.js with object-observe-lite.js. You can also use the minified versions of the same files (replacing .js with .min.js). If you want to use the "light" version on the server side, you can either directly reference the desired version with require (as in require("./node_modules/object.observe/dist/object-observe-lite.js");) or change the "main" reference in package.json.

For more details about loading the polyfill on a client, read the documentation.

Limitations and caveats

Browser support

This polyfill has been tested (and is working) in the following environments:

It also does not overwrite the native implentation in Chrome 36+, Opera 23+, node.js 0.11.13+ and io.js.

Performances

Some benchmarks have been done on the dirty checking loop. See the docs for more details.

License

The MIT License (MIT)

Copyright (c) 2015 Massimo Artizzu (MaxArt2501)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.