(1) decoration

  • Class decorator – applies to class constructors.
@sealed
class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }
    greet() {
        return "Hello, " + this.greeting;
    }
}

function sealed(constructor: Function) {
    Object.seal(constructor);
    Object.seal(constructor.prototype);
}
Copy the code
  • Method decorator – applied to the property descriptor of a method
class Greeter {
    greeting: string;
    constructor(message: string) {
        this.greeting = message;
    }

    @enumerable(false)
    greet() {
        return "Hello, " + this.greeting;
    }
}

function enumerable(value: boolean) {
    return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) {
        descriptor.enumerable = value;
    };
}
Copy the code
  • Accessor decorator – Property descriptors applied to accessors
  • Attribute decorator
  • Parameter decorator – specifies before a parameter declaration
class Greeter { greeting: string; constructor(message: string) { this.greeting = message; } @validate greet(@required name: string) { return "Hello " + name + ", " + this.greeting; } } import "reflect-metadata"; const requiredMetadataKey = Symbol("required"); function required(target: Object, propertyKey: string | symbol, parameterIndex: number) { let existingRequiredParameters: number[] = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyKey) || []; existingRequiredParameters.push(parameterIndex); Reflect.defineMetadata(requiredMetadataKey, existingRequiredParameters, target, propertyKey); } function validate(target: any, propertyName: string, descriptor: TypedPropertyDescriptor<Function>) { let method = descriptor.value; descriptor.value = function () { let requiredParameters: number[] = Reflect.getOwnMetadata(requiredMetadataKey, target, propertyName); if (requiredParameters) { for (let parameterIndex of requiredParameters) { if (parameterIndex >= arguments.length || arguments[parameterIndex] === undefined) { throw new Error("Missing required argument."); } } } return method.apply(this, arguments); }}Copy the code

www.tslang.cn/docs/handbo…

Reflect Metadata

Namespace Reflect {// For decorator metadata(k, v): (target, property?) => void // defineMetadata defineMetadata(k, v, o, p?) on the object. : void // Whether hasMetadata exists (k, o, p?) : boolean hasOwnMetadata(k, o, p?) : Boolean getMetadata(k, o, p?) : any getOwnMetadata(k, o, p?) : any // getMetadataKeys for all metadata (o, p?) : any[] getOwnMetadataKeys(o, p?) : any[] // deleteMetadata deleteMetadata(k, o, p?) : boolean }Copy the code

WeakMap<any, Map<any, Map<any, any>>> Weakmap.get (o).get(p).get(k)

(3) the Nest

Controllers

docs.nestjs.com/first-steps

Tailwind CSS

Style short for responsive

Tailwindcss.com/docs/font-s…

@ the apply method

Tailwindcss.com/docs/functi…

Configure file custom styles

Github.com/tailwindlab…

Compile attention to place purge

(5) map bed

Typeorm. IO /#/many-to-o…

Highlights: Delete useless pictures on the way to upload

  • CachePic: Stores all images
  • DbPic: Stores images that have been cached in the database
  • OldPic: Stores images to be deleted

In the business layer, after the user upload the picture, the key value of the picture is inserted into the cachePic, and after the user persists the form information, the key value of the picture is inserted into dbPic.

  • Set a scheduled task
const { bucketManager, The bucket} = await this. QiNiuService. GetManageToken () / / clear the intersection const nowDelSet = await this.cacheService.sinter(['cachePic', 'dbPic']) for (let key of nowDelSet.values() ) { this.cacheService.srem('cachePic', key) this.cacheService.srem('dbPic', key) this.cacheService.srem('oldPic', Key)} const oldDelSet = await this. CacheService. Smembers (' oldPic ') / / the old want to delete the first set of pictures deleted the if (oldDelSet) {for (let the key of oldDelSet.values() ) { this.cacheService.srem('oldPic', key) this.cacheService.srem('cachePic', key) bucketManager.delete(bucket, key, function(err, respBody, respInfo) { if (err) { console.log(err); //throw err; } else { console.log(respInfo.statusCode); console.log(respBody); }}); }} // Compare the cache and database images to find the images to delete (including the user may use), Const newDelSet = await this.cacheservice. Sdiff ('cachePic', 'dbPic') // If (newDelSet) {for (let key of newdelset.values ()) {this.cacheservice. Sadd ('oldPic', key)}}Copy the code