0.1.2 • Published 8 months ago

dtor v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Experimental TypeScript Deconstructor

Requires TypeScript 0.5.2 or newer

Example tsconfig.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

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<SomeExample>;
})()

Example using with sync deconstructors

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<SomeExample>;

Without this library

class SomeExample {
    public constructor() {
        console.log("constructed");
    }

    [Symbol.dispose]() {
        console.log("deconstructed");
    }
}

using cls = new SomeExample() as Deconstructable<SomeExample>;
0.1.0

8 months ago

0.1.2

8 months ago

0.1.1

8 months ago

0.0.2

10 months ago

0.0.1

10 months ago

0.0.0

10 months ago