Re: [heycam/webidl] Introduce the observable array type (#836)

> Is it necessary to make these types constructible? 

It's not strictly necessary, but it's good API design, per https://w3ctag.github.io/design-principles/#constructors. For example, it'd be sad if we introduced a second use of `ObservableArray` on the platform, but it was unpolyfillable, because authors were not able to construct their own `ObservableArray`s. We see this problem today with `DOMTokenList`.

However, the approach I'm currently working on (I hope to have a PR up today), per https://github.com/heycam/webidl/issues/796#issuecomment-578273849, does remove the need for a constructor, and thus lets us sidestep a lot of these questions :). I'm optimistic.

> Some thoughts about hooks. Do the after hooks provide anything useful that can't be done with before?

That's a great point.

Leaving aside the JS-constructed question for a moment, which hopefully gets oviated by the Proxy-based approach, and talking purely about spec authorship: I think the main benefit of the after hooks is that when they run, your array is entirely consistent. So e.g. if you wanted to express "set the UA's X to the observable array contents", you could do that pretty easily in an after hook, whereas in a before hook, you would have to communicate that you want the current observable array contents, with the new item inserted at the right place, to be used to update the UA's X.

> Of course, if it was done that way, the implementation would want to replace getting as well. Not sure why this more complex way.

I think having the spec author provide getter/setter algorithms, as is currently done for indexed getters/setters in Web IDL, doesn't work when author mutation is allowed. The spec-author-provided getter, in particular, can't be sure what to get, if there have been author mutations in the meantime. Or, well, it can, but doing so would require adding spec text to the setter to track all such mutations. This approach attempts to move all that bookkeeping into the Web IDL spec, so that the spec author can instead use the always-updated "backing observable array contents" list, plus the hooks to react to changes to that list.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/heycam/webidl/pull/836#issuecomment-579340148

Received on Tuesday, 28 January 2020 16:37:42 UTC