Home > front end >  How do you subclass a backdraft component and include watchables?
How do you subclass a backdraft component and include watchables?

Time:12-10

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?

CodePudding user response:

Yes, this feature is available by writing

class AnchorSteam extends withWatchables(Beer, 'foamy') {
    [...component code goes here]
}

withWatchables is a function exported by the watchUtils module:

https://github.com/altoviso/backdraft/blob/master/src/watchUtils.js#L762

A common use case is adding a watchable to a component...

class Beer extends withWatchables(Component, 'temperature') {
    [...component code goes here]
}

Indeed, this is so common, there the library provides some "expression sugar" (that is, it's not really shorter, but seems to read better):

class Beer extends Component.withWatchables('temperature') {
    [...component code goes here]
}
  • Related