1.2.1 • Published 4 years ago

ts-decontainer v1.2.1

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

ts-decontainer

Creating class decorator

import {CreateClassDecorator} from "ts-decontainer";
export const Controller = CreateClassDecorator("controllers", (value, f) => {
  return {
    type: "json",
    target: f,
    path: value
  }
})

Using class decorator:

@Controller("/user") // "/user" is value prop
class UserController {
  // cool things
}

Creating decorator factory

import {CreateDecoratorFactory} from "ts-decontainer";

const Route = CreateDecoratorFactory("routes",
  (value, target, propertyKey, descriptor) => {
    // do something

    return {
      ...value,
      function: descriptor.value
    } // return a object for describing your function
  });

Using this decorator:

class A {

  @Route()
  public classMethod() {
    // doing awesomethings
  }

  @Route({
    // can add property. this poperties are your "value" parameter.
    // "Creating decorator factory" section
    method: "post" 
  })
  public otherClassMethod() {
    // doing awesomethings
  }

}

Getting marked globals:

Container.getAll();
// eg. return
// {
//   routes: [
//      { function: [Function: classMethod] },
//      { method: 'post', function: [Function: otherClassMethod] }
//    ],
//   controllers: [
//     { type: 'json', target: [Function: UserController], path: '/user' }
//   ]
// }

// or specially select
Container.get("routes")
// returns:
// [
//   { function: [Function: classMethod] },
//   { method: 'post', function: [Function: otherClassMethod] }
// ]
1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago