class Beer extends Component {
[...component code goes here]
}
class AnchorSteam extends Beer.withWatchables('foamy') {
[...component code goes here]
}
Will this work? Can I add watchables on the subclassed component?
Secondary question:
If instead I did this...
class Beer extends Component.withWatchables('foamy') {
[...component code goes here]
}
class AnchorSteam extends Beer {
[...component code goes here]
}
... would AnchorSteam respond to the 'foamy' watchable, e.g. if I have a bdReflect: foamy
in AnchorSteam, will it respond to changes in the watchable?
Yes, this feature is available by writing
withWatchables
is a function exported by thewatchUtils
module:https://github.com/altoviso/backdraft/blob/master/src/watchUtils.js#L762
A common use case is adding a watchable to a component...
Indeed, this is so common, there the library provides some "expression sugar" (that is, it's not really shorter, but seems to read better):
Regarding the second question: yes,
AnchorSteam
has the watchablefoamy
. There is nothing special going on here.Beer
has a standard javascript getter/setter forfoamy
as part of its interface;AnchorSteam
is a subclass ofBeer
and therefore will also have the getter/setter forfoamy
(assumingAnchorSteam
has not overridden that getter/setter in the superclass).The second question also asked if
bdReflect
would work inAnchorSteam
. Again, the answer is yes.