-
Notifications
You must be signed in to change notification settings - Fork 18
How should ArrayBuffer and SharedArrayBuffer be extended? #40
Comments
2 > 1 for me, and I'm undecided on 3. I don't think the |
Anecdotal as always, but Twitter poll is currently leading with option 2. I like that one the most too right now. |
For option 2, how do folks feel about having a more explicit property name with the word "resizable" in it, like |
@DanielRosenwasser Any thoughts from TypeScript from a type checking point of view about this removal of the separate |
People who will want to ensure We'll inevitably get the request to disable |
Decided on 2, closing. |
There are three options:
Optional second parameter for
maxByteLength
:new ArrayBuffer(initial, maxByteLength)
.Problem: Possible web incompat.
new ArrayBuffer(10, 5)
doesn't throw right now but would start throwing.new ArrayBuffer(10, 20)
would get new, different behavior.Optional second option bag with
maxByteLength
property:new ArrayBuffer(initial, { maxByteLength: N })
Has precedent in e.g.
new Error(msg, { cause: ... })
Problem: Still possible incompat, but exceedingly unlikely. I doubt there's any code in the wild that's passing an object into the second parameter with a
maxByteLength
property.Static factory method:
ArrayBuffer.resizable(initial, maxByteLength)
(suggested by @jandem)Has precedent in e.g.
Proxy.revocable
andArray.from
, though theArray.from
analogy is a little weaker, as it's not creating a new kind of Array, but purely a convenience factory function.Problem: (from @bmeck) Need to mindful of composition with higher-order collection methods like
Array.prototype.map
.The disadvantages of (1) outweigh its advantages, so I think the real choice is between (2) or (3). Given we have precedent for both, I'm leaning towards (2) since there's no possibility of any footguns with higher-order collection methods.
Also, I'm imagining that if I'm writing library code that may or may not make a resizable buffer, having an options bag meaning we can have a single construction site instead of having to decide whether to call
new ArrayBuffer()
orArrayBuffer.resizable
.The text was updated successfully, but these errors were encountered: