繁体   English   中英

NgRx 数据服务更新删除 object 原型,而不是更新更改的字段

[英]NgRx Data service Update removes object prototype instead of updating the changed fields

当我的 NgRx DefaultDataService 更新时,它会删除存储中对象的类型/原型。 这些对象不再是 Todo 类型,而是没有原型的简单对象。

对象来自服务器作为符合 Todo接口的 json 对象。 我 pipe 将它们作为 Todo对象输入到存储中,如下所示:

@Injectable()
export class TodosDataService extends DefaultDataService<ITodo> {
    baseUrl;

constructor( http: HttpClient, httpUrlGenerator: HttpUrlGenerator) {
    super("Todos", http, httpUrlGenerator);
}

getAll(): Observable<Todo[]> {

    //HERE - the ITodo[] from server is mapped to Todo[], then saved to store
    return super.getAll().pipe(
        map(todosList => todosList.map(todoData => new Todo(todoData)))
    );
}

但是在此服务的 update() 覆盖方法上管道它们不起作用:

update(updatedTodo: Update<Todo>): Observable<Todo> {
    return super.update(updatedTodo).pipe(map(data => new Todo(data)));
}

注意:我也尝试过手动使用我自己的 httpClient.put 请求,而不使用 DefaultDataService 的超级调用和其他几种方式。

问题在于,当ngrx 将增量(更改)应用于商店中的 object 时,它在某种程度上不再是待办事项 object 这是运行上述语句后控制台的屏幕截图:

Todo 原型已消失

这会导致意外行为。

TL;DR:我们如何确保更新不会删除原型? 如果这不可能,是否有一种简单的方法可以在更新到达商店之前拦截更新,以提供自定义实现?

此行为旨在查看以下 GitHub 问题以获取更多信息。 https://github.com/ngrx/platform/issues/1641

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM