consider adding `set*` methods for all properties
See original GitHub issueDo you want to request a feature or report a bug?
Improvement.
What’s the current behavior?
Right now the Immutable.js .set
and .merge
methods are still used for some cases (eg. setting anchorKey
on a range, or isVoid
on a node) by users as the public API. They’re not really encouraged at all, but not explicitly discouraged.
But I think this isn’t great because it makes things harder to validate/migrate when APIs change. For example, if isBackward
is removed, there’s no way to offer a deprecation warning if people are doing range.set('isBackward', false)
because it will just error out.
What’s the expected behavior?
Instead, it might be nice for all models to expose setter methods of .set*()
for each of their properties, that can be the canonical way to change properties in a low-level manner. This way they can have type validations, normalizations, etc. since they are custom methods.
For example:
range.setIsFocused(true)
node.setNodes(nodes)
value.setDocument(document)
Or in the newer Range/Point
combination:
range.setAnchor(anchor)
point.setOffset(offset)
They are still low-level, and rarely used, but they are at least standardized and more flexible in terms of versioning/improving the API over time.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
I’ll just stash it for now, it might very well not be needed at all depending on the solution we’re replacing
immutablejs
with (if we’re usingimmer
then I don’t think we need anything from this).Yup, not going to end up needing this. Once we drop Immutable.js in favor of using
immer
we won’t need to have setter functions at all!