-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The length of an array should not be observed #5
Comments
Oops, I should have said : "It would be great if your library polyfilled Array.observe as well, it's the same except that non-enumerable properties should not be included" :) Thank you. |
Yes, it does. I tried in both Chrome and io.js. Use this snippet: var a = [];
Object.observe(a, console.log.bind(console));
a.push("foo");
// [ { type: 'add', object: [ 'foo' ], name: '0' },
// { type: 'update', object: [ 'foo' ], name: 'length', oldValue: 0 } ] Unless, of course, I misunderstood what you mean. |
Oh, ok, I posted second after your update :)
For the cases it can effectively be polyfilled, there's the caveat of changing the |
Thank you for your super-quick answer ! Sorry, I missed that part of the doc :s Very interesting, you know your subject inside out :) I see that you seek perfection and that's admirable, but I personnaly wouldn't be worried about the splice events and wouldn't try to change the Array prototype at all for push and all. It's true that we lose some semantics about how an array was added/removed/updated, but I guess most people are more interested by the mere fact that it's now in the array. The guys at observe-js, whom I believe also made the spec for some of them, even report update events as delete+add events to the user. I think it's a shame to ignore semantics like that and, although it can be quite handy for most people (I added a |
A way to avoid messing with native prototypes would involve changes in the property checker itself. It should take special measures for objects that have the |
You know more about these things than I do, but I see no algorithm that can truly distinguish a splice when updates are involved.
As you probably know, observe-js uses a distance algorithm to detect splices as much as possible: https://github.com/Polymer/observe-js/blob/master/src/observe.js#L1303 |
Chrome observes length on arrays. |
This polyfill is amazing. Great work! I was exploring other options and nothing comes close to this. The solution is the best out there. I want to give a suggestion for the If you know a great polyfill for |
No, I'm not aware of any close polyfill for I've been thinking about a separate polyfill for Now, should those two polyfill be independent or not? On the basis of what I just said, they can't, since they should operate on each other's observed objects. This would mean finding a (rather awkward) way to making them interoperate, like publically exposing the If the polyfills are conceived as independent, they'd lose the method equivalence stated above, forcing the developers to strictly using As soon as I have a weekend that doesn't gobble all my spare time in other stuff, I think I'll spend some of it brainstorming on the problem and (finally) putting down some code. In the meanwhile, all the suggestions are welcome! Edit: also I'm quite eager to try jsblocks sooner or later - looks veeeery nice! Kudos on the excellent work. |
Opened issue #10 for |
@astoilkov I followed your advice for the time being, and created a separate polyfill for I actually hope it will be short-lived, as that would mean I'll come with a decent solution soon(ish). |
Wow. Great work. I took a look at the code and it looks really simple. I am happy to see this thing implemented. You are the first to do something like this. Can't wait to try it out in one of my projects. |
The native O.o does not return a change event for the
length
property of arrays.The text was updated successfully, but these errors were encountered: