https://github.com/bsdelf/forwardit
Forwarding marker and installer.
https://github.com/bsdelf/forwardit
forward forwardable forwarding javascript typescript
Last synced: 3 months ago
JSON representation
Forwarding marker and installer.
- Host: GitHub
- URL: https://github.com/bsdelf/forwardit
- Owner: bsdelf
- Created: 2020-05-07T10:26:56.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-13T08:47:22.000Z (about 5 years ago)
- Last Synced: 2025-02-13T05:44:52.918Z (4 months ago)
- Topics: forward, forwardable, forwarding, javascript, typescript
- Language: TypeScript
- Homepage:
- Size: 55.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# forwardit
Forwarding marker and installer.
## Installation
```
npm i forwardit
```## Usage
Basic usage in JavaScript:
```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); // 0, 0broker.inc();
console.log(broker.value, data.value); // 1, 1data.inc();
console.log(broker.value, data.value); // 2, 2uninstallForwards(broker, data);
console.log(broker.value, data.value); // undefined, 2
```For TypeScript, we need to argument broker's type information to avoid compiler errors and make code completion working correctly:
```typescript
// declare Broker as usual
class Broker {
// Broker's own properties
}// argument Broker with selected properties from Data
interface Broker extends Pick {}// create instances, install forwards...
// now code completion works for "value" and "inc", no more compiler errors
broker.value;
broker.inc;
```