Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I should be able to modify State's getters and setters for an individual attribute #227

Open
pixelpax opened this issue Jan 28, 2016 · 4 comments

Comments

@pixelpax
Copy link

I want to be able to follow some procedure every time an attribute is modified. For example if I wanted a vector object whose x and y components should be interdependent with its polar components, magnitude and direction, I cannot make all four of these numbers derived objects because their interdependence becomes circular. What I would like to do instead is initialize the 'x' prop with a 'set' function, to automatically update the polar coordinates, etc.

Ampersand-State allows you to specify the 'set' behavior for a dataType as a whole, but this only works if I want to modify all 'number' values to have the same setting behavior.

If there is a more trivial way to accomplish what I'm describing, I would be interested.

@pixelpax
Copy link
Author

I'll start working on this actually, it doesn't look too difficult.

@wraithgar
Copy link
Contributor

Historically people have set up custom data types for cases like this, and is just the sort of problem that was trying to be solved when custom data types were added.

Have you tried that? Or is there some reason why a attribute-level override would be better?

@pixelpax
Copy link
Author

In my opinion (which may be uninformed) there are two reasons why this solution isn't enough:

  1. Because sometimes one wants to treat different attributes with the same datatype differently. Take for example the scenario with a vector type that has dual representations. We want to change what happens 'x' and 'mag' are set, but in different ways. Since both are numbers, we can't change one's set method without changing both.
  2. I imagine it would be common to want to change the 'set' behavior on a primitive attribute. Users should be able to do this as simply as possible, by adding a 'set' method onto the prop. To do so right now requires that one create a an entirely new and disjointed sub-object within the state to specify the behavior of the custom dataType. They shouldn't have to rewrite the compare function or worry about casting, since these are already taken care of by default behavior. It does work-- if one only has one primative they want to customize like this --but it seem unintuitive and little verbose (from the perspective of someone who is just beginning to use Ampersand like myself).

@wraithgar
Copy link
Contributor

Your opinion was in fact very informed, and from a very valuable perspective. Please do consider submitting a PR for this. I for one would look forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants