Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/berendsliedrecht/dtor
https://github.com/berendsliedrecht/dtor
Last synced: 22 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/berendsliedrecht/dtor
- Owner: berendsliedrecht
- License: mit
- Created: 2023-07-01T12:55:00.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-30T07:44:00.000Z (about 1 year ago)
- Last Synced: 2024-09-14T09:14:32.388Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Experimental TypeScript Deconstructor
Requires TypeScript 0.5.2 or newer
## Example tsconfig.json
```json
{
"compilerOptions": {
"lib": ["esnext", "dom"],
"target": "es2015",
"module": "commonjs",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"outDir": "build",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": true
}
}
```## Example using with async deconstructors
```typescript
import type { AsyncDeconstructable } from 'dtor'
import { Deconstructor } from "dtor";class SomeExample {
public constructor() {
console.log("constructed");
}@Deconstructor()
public async asyncDeconstructor() {
await new Promise((r) => setTimeout(r, 2000));
console.log("deconstructed");
}
}void (async () => {
await using cls = new SomeExample() as AsyncDeconstructable;
})()```
## Example using with sync deconstructors
```typescript
import type { Deconstructable } from 'dtor'
import { Deconstructor } from "dtor";class SomeExample {
public constructor() {
console.log("constructed");
}@Deconstructor()
public deconstructor() {
console.log("deconstructed");
}
}using cls = new SomeExample() as Deconstructable;
```## Without this library
```typescript
class SomeExample {
public constructor() {
console.log("constructed");
}[Symbol.dispose]() {
console.log("deconstructed");
}
}using cls = new SomeExample() as Deconstructable;
```