1.0.1 • Published 29 days ago

mesh-decorators v1.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
29 days ago

Mesh Decorators

Small framework for creating custom decorators for use with Mesh IoC.

Usage

import { createMemberDecorator, findMembers, invokeMethods } from 'mesh-decorators';

// 1. Create a decorator to track "init" methods
const init = createMemberDecorator('init');

class FooService {

    // 2. Decorate members of the classes (can apply to methods and/or properties)
    @init()
    async setup() { /* ... */}

}

// 3. Bind the service(s) to a mesh
const mesh = new Mesh();
mesh.service(FooService);

// 4. Get all references to members decorated with @init
const initHandlers = findMembers('init', mesh);
// [{ target: <instance of FooService>, memberName: 'setup' }]

// 5. Invoke all @inmit methods
await Promise.all(invokeMethods('init', mesh));

License

ISC © Boris Okunskiy

1.0.1

29 days ago

1.0.0

1 month ago