question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

consider adding `set*` methods for all properties

See original GitHub issue

Do 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:closed
  • Created 5 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Dundercovercommented, Nov 26, 2018

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 using immer then I don’t think we need anything from this).

0reactions
ianstormtaylorcommented, Aug 31, 2019

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I override get and set methods for all properties in a ...
I have got several classes looking like the one below, and I need to do some checks in the get method and custom...
Read more >
Using Properties - C# Programming Guide - Microsoft Learn
Properties combine aspects of both fields and methods. To the user of an object, a property appears to be a field, accessing the...
Read more >
Python's property(): Add Managed Attributes to Your Classes
In this step-by-step tutorial, you'll learn how to create managed attributes, also known as properties, using Python's property() in your custom classes.
Read more >
Properties (Java Platform SE 8 ) - Oracle Help Center
Because Properties inherits from Hashtable , the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged...
Read more >
C# Properties (Get and Set) - W3Schools
The set method assigns a value to the name variable. The value keyword represents the value we assign to the property. If you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found