代码之家  ›  专栏  ›  技术社区  ›  MattTreichel

为什么NgRx操作类型被格式化为非强制的“[Source]Event”字符串?

  •  0
  • MattTreichel  · 技术社区  · 7 年前

    接口只有一个属性,类型,用字符串表示。type属性用于描述将在应用程序中调度的操作。类型的值以[Source]事件的形式出现,用于提供操作类别的上下文,以及从何处调度操作。

    https://ngrx.io/guide/store/actions

    我想知道不强制这种任意字符串格式的基本原理或好处是什么?为什么不让行动强制你定义 source 和 event type 属性?它似乎给错误留下了空间,使得很容易忽略推荐的格式。这有什么好处吗?

    0 回复  |  直到 7 年前
        1
  •  1
  •   xandermonkey    7 年前

    import { createAction, props } from '@ngrx/store';
    import { Config } from '../models/config.model';
    
    const appAction = '[App]';
    
    export const getConfig = createAction(
      `${appAction} Get Config`
    );
    
    export const setConfig = createAction(
      `${appAction} Set Config`,
      props<{ config: Config }>()
    );
    
    

    这是一个切向相关的 article