You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DOMMatrix has mutating multiplySelf() and preMultiplySelf(), while DOMMatrixReadOnly has only the non-mutating multiply() but not preMultiply().
It would be nice to add preMultiply for consistency. Similar for other *ReadOnly geometry classes if needed.
As an alternative, instead of adding more methods to *ReadOnly as it has elsewhere been discussed that the *ReadOnly pattern is a direction we wish we didn't take (that's why there's DOMQuad but not DOMQuadReadOnly), we should consider adding a new pattern of methods for working with immutability vs not.
I propose adding clone() and copy() methods, and then people can pursue immutability like so:
As a real-world example, pretty much all Three.js classes have clone() and copy() methods. Many of their methods also accept targets, for example obj.doSomething() (writes to self) vs obj.doSomething(other) writes to other instead of self.
I believe that the approach Three.js takes is nice because it is more concise (methods that can be mutable or not mutable, insead of double the amount of methods for mutable vs not).
The text was updated successfully, but these errors were encountered:
trusktr
changed the title
[geometry-1] DomMatrixReadOnly is missing preMultiply() method (and the idea of better mutable vs immutable patterns)
[geometry-1] DomMatrixReadOnly is missing preMultiply() method (better mutable vs immutable patterns?)
Dec 28, 2024
There'd be something nice about the non-mutable (non-*Self) methods, in that returning a *ReadOnly interfaces allows immutability to be enforced when the performance tradeoff is acceptable.
With methods like clone() and copy(), and methods that create new instances or write to targets, immutable behavior can be applied, but not strictly enforced. You could return mat.clone().rotateSelf(10) and someone might think that modifying the returned value will do something when in fact it does not.
For people who choose to have immutable designs, the non-*Self methods would seem to be desirable if they were to return *ReadOnly interfaces, but right now clone() and copy() patterns would be nicer if the non-*Self methods continue to return mutable interfaces.
We should at least go one direction or the other, rather than stay stuck in the middle.
DOMMatrix
has mutatingmultiplySelf()
andpreMultiplySelf()
, whileDOMMatrixReadOnly
has only the non-mutatingmultiply()
but notpreMultiply()
.It would be nice to add
preMultiply
for consistency. Similar for other*ReadOnly
geometry classes if needed.As an alternative, instead of adding more methods to
*ReadOnly
as it has elsewhere been discussed that the*ReadOnly
pattern is a direction we wish we didn't take (that's why there'sDOMQuad
but notDOMQuadReadOnly
), we should consider adding a new pattern of methods for working with immutability vs not.I propose adding
clone()
andcopy()
methods, and then people can pursue immutability like so:or
As a real-world example, pretty much all Three.js classes have clone() and copy() methods. Many of their methods also accept targets, for example
obj.doSomething()
(writes to self) vsobj.doSomething(other)
writes toother
instead of self.I believe that the approach Three.js takes is nice because it is more concise (methods that can be mutable or not mutable, insead of double the amount of methods for mutable vs not).
The text was updated successfully, but these errors were encountered: