github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/design/slack-ts/deco.ts (about)

     1  
     2  function Workspace(constructor: Function) {
     3      Object.seal(constructor);
     4      Object.seal(constructor.prototype);
     5  }
     6  
     7  function Doc(constructor: Function) {
     8      Object.seal(constructor);
     9      Object.seal(constructor.prototype);
    10  }
    11  
    12  
    13  function format(formatString: string) {
    14      return function (target: Object, propertyKey: string) {
    15          let value: string;
    16      }
    17  }
    18  
    19  function OuterList(target: Object, propertyKey: string) {
    20  
    21  }
    22  
    23  // function OuterList() {
    24  //     return function (target: Object, propertyKey: string) {
    25  //         let value: string;
    26  //     }
    27  // }
    28  
    29  function ListSize_Huge() {
    30      return function (target: Object, propertyKey: string) {
    31          let value: string;
    32      }
    33  }
    34  
    35  function ListSize_Small() {
    36      return function (target: Object, propertyKey: string) {
    37          let value: string;
    38      }
    39  }
    40  
    41  function Min(limit: number) {
    42      return function (target: Object, propertyKey: string) {
    43          let value: string;
    44          const getter = function () {
    45              return value;
    46          };
    47          const setter = function (newVal: string) {
    48              if (newVal.length < limit) {
    49                  Object.defineProperty(target, 'errors', {
    50                      value: `Your password should be bigger than ${limit}`
    51                  });
    52              }
    53              else {
    54                  value = newVal;
    55              }
    56          };
    57          Object.defineProperty(target, propertyKey, {
    58              get: getter,
    59              set: setter
    60          });
    61      }
    62  }
    63  
    64  function color(value: string) {
    65      // this is the decorator factory, it sets up
    66      // the returned decorator function
    67      return function (target) {
    68          // this is the decorator
    69          // do something with 'target' and 'value'...
    70      };
    71  }
    72  
    73  function first() {
    74      console.log("first(): factory evaluated");
    75      return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    76          console.log("first(): called");
    77      };
    78  }
    79  
    80  function second() {
    81      console.log("second(): factory evaluated");
    82      return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
    83          console.log("second(): called");
    84      };
    85  }