forwardit
Forwarding marker and installer.
Installation
npm i forwardit
Usage
Basic usage in JavaScript:
const { forward, installForwards, uninstallForwards } = require('forwardit');
class Data {
@forward
value = 0;
@forward
inc() {
this.value++;
}
}
const data = new Data();
const broker = {};
installForwards(broker, data);
console.log(broker.value, data.value);
broker.inc();
console.log(broker.value, data.value);
data.inc();
console.log(broker.value, data.value);
uninstallForwards(broker, data);
console.log(broker.value, data.value);
For TypeScript, we need to argument broker's type information to avoid compiler errors and make code completion working correctly:
class Broker {
}
interface Broker extends Pick<Data, 'value' | 'inc'> {}
broker.value;
broker.inc;