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
withWatchablesis a function exported by thewatchUtilsmodule: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,
AnchorSteamhas the watchablefoamy. There is nothing special going on here.Beerhas a standard javascript getter/setter forfoamyas part of its interface;AnchorSteamis a subclass ofBeerand therefore will also have the getter/setter forfoamy(assumingAnchorSteamhas not overridden that getter/setter in the superclass).The second question also asked if
bdReflectwould work inAnchorSteam. Again, the answer is yes.