[NgRx] NgRx Entity Adapter Configuration - Understanding sortComparer and selectId
import { Course, compareCourses } from "../model/course";
import { EntityState, createEntityAdapter } from "@ngrx/entity";
import { createReducer, on } from "@ngrx/store";
import { CoursesAction } from "../actions-types";
/*
export interface CoursesState {
entities: { [key: number]: Course };
ids: number[];
}*/
export interface CoursesState extends EntityState<Course> {
/**Extend the entity here */
allCoursesLoaded: boolean;
}
export const adapter = createEntityAdapter<Course>({
sortComparer: compareCourses
// selectId: course => course.id // NgRx use 'id' by default
});
export const initCoursesState = adapter.getInitialState({
allCoursesLoaded: false
});
export const coursesReducer = createReducer(
initCoursesState,
on(CoursesAction.allCoursesLoaded, (state, action) =>
adapter.addAll(action.courses, { ...state, allCoursesLoaded: true })
)
);
export const { selectAll } = adapter.getSelectors();
export function compareCourses(c1:Course, c2: Course) {
const compare = c1.seqNo - c2.seqNo;
if (compare > 0) {
return 1;
}
else if ( compare < 0) {
return -1;
}
else return 0;
}
'sortCompoarer' is used with adapter when you want to sort the entites based on one prop, 'ids' will be also sorted accordingly to the new entities.
[NgRx] NgRx Entity Adapter Configuration - Understanding sortComparer and selectId的更多相关文章
- [NgRx] NgRx Data Fetching Solution - How to Load Data Only If Needed
We have a reoslver, which everytime we want visit '/courses' route, it will be triggered, then api w ...
- Method not found: 'System.Data.Entity.ModelConfiguration.Configuration.XXX
使用EF flument API 修改映射数据库字段的自增长 modelBuilder.Entity<Invoice>().Property(p => p.Id).HasDatab ...
- 【EF框架异常】System.MissingMethodException:“找不到方法:“System.Data.Entity.ModelConfiguration.Configuration.PrimitivePropertyConfiguration
最近调试EF的时候遇到下面这个问题 System.MissingMethodException:“找不到方法:“System.Data.Entity.ModelConfiguration.Config ...
- OpenOCD Debug Adapter Configuration
Correctly installing OpenOCD includes making your operating system give OpenOCD access to debug adap ...
- [NgRx] NgRx Runtime Checks
Turn on runtime check: @NgModule({ declarations: [AppComponent], imports: [ ..., StoreModule.forRoot ...
- [NgRx 8] Basic of NgRx8
1. First step is creating action creator Action name should be clear which page, which functionality ...
- [转]Porting to Oracle with Entity Framework NLog
本文转自:http://izzydev.net/.net/oracle/entityframework/2017/02/01/Porting-to-Oracle-with-Entity-Framewo ...
- Entity Framework 教程——创建实体数据模型
创建实体数据模型: 本文将带你创建实体数据模型(EDM)SchoolDB数据库和理解基础建设模块. 实体数据模型(EDM)是用于描述实体之间关系的一种模型,以下将使用Visual Studio 201 ...
- Entity Framework 6连接Postgresql、SQLite、LocalDB的注意事项和配置文件
Postgresql Postgresql支持Code First的方式自动生成表,不过默认的模式是dbo而不是public,而且还可以自动生成自增主键. <?xml version=" ...
随机推荐
- 【转】用chrome滚动截屏
用开发者常用的网站chrome,打开需要截屏的网页 使用快捷键组合:Alt + Command + I (Mac) || Ctrl + Shift + I (Windows) 使用快捷键组合来打开命令 ...
- core文件问题
core文件问题 Linux系统core涉及到的问题 core文件的问题具体可以参照系统的man手册(man core) 能否生成core文件 ulimit -c 磁盘权限问题 进程权限问题 生成co ...
- java.lang.SecurityManager、java.security包
学习java大概3年多了,一直没有好好研究过java安全相关的问题,总是会看到 SecurityManger sm = System.getSecurityManager(); if(sm!=null ...
- 【转载】终于有人把“TCC分布式事务”的实现原理讲明白了
之前网上看到很多写分布式事务的文章,不过大多都是将分布式事务各种技术方案简单介绍一下.很多朋友看了还是不知道分布式事务到底怎么回事,在项目里到底如何使用. 所以这篇文章,就用大白话+手工绘图,并结合一 ...
- zookeeper集群搭建及ZAB协议
zookeeper集群搭建非常简单,准备三台安装好zookeeper服务器,在其zoo.cfg配置中分表添加如下配置 initLimit 10 集群中的follower与leader之间完成初始化同步 ...
- 未检测到.NET CORE SDK 或者 新建项目没有.NET CORE 3.0选择项
终于解决了 首先先看自己的VS2019版本 由于楼主下载的 .NET CORE SDK 3.0.100-preview8-013656 焕然大悟 原来是版本不符合,需要用vs 2019 preview ...
- NetworkInterface网速监测
private NetworkInterface[] nicArr; //网卡集合 private Timer timer; //计时器 public MainWindow() { Initializ ...
- 【开发笔记】- Linux命令大全
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...
- 智慧图携手DataPipeline,让实体商业更智慧!
近日,国内领先的实体商业数字化运营服务商智慧图携手DataPipeline,基于专业的数据集成与应用基础展开了合作. 未来DataPipeline将通过不断提升自身产品和服务实力,与智慧图一道致力于帮 ...
- QString 转 LPCWSTR
遍历文件的时候遇到的一个问题,百度了好久才搞定,这个是可用的,所以总结下来. QString 转 LPCWSTR QString path1 = path + "\\*"; con ...