0
典型情况:我通过http获取数据并将它们存储到ngrx/store中。但数据包含字符串而不是JS Date对象。我应该在哪里转换它们?将字符串转换为日期的位置?
- 在服务
this.http(...).map(convert).subscribe(store.dispatch(new AddAction))
- 在店内
case add: convert(payload); return state
还是在行动的减速机:
export class AddMany implements Action { readonly type = addMany constructor(public payload: FinishedCall[]) { this.payload = this.convertData(payload) } }
我想我应该做的服务,但我怕获得非常大的服务文件
这取决于你和业务对象的设计。如果您更喜欢在打字稿代码中始终使用JS Date类型,则尽可能早地将其转换为JS Date并尽可能从JS Date转换为字符串(如果也是必要的话)。创建一些辅助方法来进行转换(如有必要),并在决定实现此目的的任何地方重新使用这些方法。 – Igor
我宁愿尽快将日期转换为日期 – x1site
好的,那么你就知道你的问题的答案。 – Igor