Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.
/ ts-decontainer Public archive

Basically; creates a decorator and globally collect all same types

License

Notifications You must be signed in to change notification settings

curefatih/ts-decontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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] }
// ]

About

Basically; creates a decorator and globally collect all same types

Resources

License

Stars

Watchers

Forks

Packages

No packages published