zoukankan      html  css  js  c++  java
  • [Typescript] Namespaces

    In general, it is not recommeded to use Namespace in Typescript, we should use ES6 module export import syntax.

    But there are still some good usecases for Namespace, for example when you defining Actions in Ngrx or Ngxs. You can group action by namespace.

    Considering two example:

    Without namespace:

    export class AddTodo {
      static readonly type = '[Todo] Add';
      constructor(public payload: any) {}
    }
    
    export class EditTodo {
      static readonly type = '[Todo] Edit';
      constructor(public payload: any) {}
    }
    
    export class FetchAllTodos {
      static readonly type = '[Todo] Fetch All';
    }
    
    export class DeleteTodo {
      static readonly type = '[Todo] Delete';
      constructor(public id: number) {}
    }

    With namespace:

    export namespace Todo {
      export class Add {
        static readonly type = '[Todo] Add';
        constructor(public payload: any) {}
      }
    
      export class Edit {
        static readonly type = '[Todo] Edit';
        constructor(public payload: any) {}
      }
    
      export class FetchAll {
        static readonly type = '[Todo] Fetch All';
      }
    
      export class Delete {
        static readonly type = '[Todo] Delete';
        constructor(public id: number) {}
      }
    }
  • 相关阅读:
    A visual proof that neural nets can compute any function 2
    Matrix
    Formula
    ID and CLASS
    hugeng007_diary01_the living way
    the mathematical knowledge
    sys.argv[]
    The Convolutional Networks
    DVWA之XSS (跨站脚本攻击)存储型+反射型。
    DVWA之 File Inclusion 文件包含
  • 原文地址:https://www.cnblogs.com/Answer1215/p/12202184.html
Copyright © 2011-2022 走看看