Skip to content

Latest commit

 

History

History
85 lines (67 loc) · 2.65 KB

lang.md

File metadata and controls

85 lines (67 loc) · 2.65 KB

lang

  • Binder : Provides to bind all methods of the instance when construct.
  • Type: Provides define new Type by some default methods. It is useful when cloning or merging. (isEmpty, isPrimitive, isJsonType, isNativeType, getClone, getName, getSize, equals)
Usage Class :

Provides to bind all methods of the instance when construct.

  • extend Binder
import { Binder } from "wasabi-common"

export default class MyClass extends Binder {
    private props;
    public constructor(props) {
      super();
      this.props = props;
    }
    
    // exampleMethod will bind when MyClass construct
    exampleMethod(){
        
    }
}
  • static call example Binder.bindAll(instance)
 import { Binder } from "wasabi-common"
 
 export default class MyClass {
     private props;
     public constructor(props) {
         Binder.bindAll(this);
         this.props = props;
     }
     
     // exampleMethod will bind when MyClass construct
     exampleMethod(){
         
     }
 }
Usage Type:

Provides define new Type by some default methods. It is useful when cloning or merging. (isEmpty, isPrimitive, isJsonType, isNativeType, getClone, getName, getSize, equals)

  • What'is benefit of use Type class: Before check Types class. As you can see you can add Type instance to Types. After that if you clone, getSize ex. methods. Types recursively find types and call their methods.
  • Some Type already defined. (Number, Boolean, Array, String, Date, RegExp: , Null, Function, Undefined, Object)

-- Define example type. (This is Function Type)

import { Type } from "wasabi-common";
let functionType = new Type<Function>({
    isPrimitive: (): boolean => false,
    isJsonType: (): boolean => false,
    getSize: (o: Function): number => {
        return (o as any).toString().length * 2;
    }
}

const f1 = function Example() {
    console.log("Example function");
}
  • After you define type you can use below methods to check or get something from the type.
functionType.isEmpty(f1); // false
functionType.isPrimitive(f1); // false
functionType.isJsonType(f1); // false
functionType.isNativeType(f1); // true
functionType.getClone(f1); // same instance f1
functionType.getName(f1); // Function
functionType.getSize(f1); // 59 charachter * 2 = 118
functionType.equals(f1, f1); // true