Let sub classes easily override the SkateJS accessors #1529
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Requirements
Rationale
Before this change, it was not possible to do this:
Implementation
This change makes it possible in the simplest way: instead of caching
props
stuff on the leaf-most classes, this caches stuff on the class that is generated by thewithUpdate
mixin.Before, it was not possible to define your own setters/getters because you would then be forfeting SkateJS functionality (or having to re-implement it).
So this change makes it so that subclasses can call SkateJS setters/getters by taking advantage of
super
.Open questions
In this implementation, if two or more subclasses define a prop with the same name, then they'll both use the same setter/getter on the withUpdate base class. I think this is fine, unless I overlooked something.
Basically, the class returned from
withUpdate
will contain all the setters/getters for all the props of all classes extending from it, but I think this has no impact on end users making the sub classes, they won't think about it.The getters/setters will anyways always be called with
this
set to the relevant instance, and the logic is always the same.So in fact, this should improve memory usage by some degree because now there won't be duplicate getters/setters per leaf class, but rather shared in the base class.
I'm not sure how this would apply in
v6
yet, but this is what I had to do so that I could stickwithUpdate
on one of my base classes, then I was able to selectively triggerwithUpdate
logic in certain cases (like my above example).In my use case, I need to be able to do this:
or