本文整理汇总了TypeScript中@ngrx/entity.EntityAdapter.getInitialState方法的典型用法代码示例。如果您正苦于以下问题:TypeScript EntityAdapter.getInitialState方法的具体用法?TypeScript EntityAdapter.getInitialState怎么用?TypeScript EntityAdapter.getInitialState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ngrx/entity.EntityAdapter
的用法示例。
在下文中一共展示了EntityAdapter.getInitialState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reducer
export interface FolderState extends EntityState<Folder> {
foldersLoaded: boolean;
foldersLoading: boolean;
folderDetails: any;
folderDetailsLoaded: boolean;
folderDetailsLoading: boolean;
selectedFolder: Folder;
}
export const adapter: EntityAdapter<Folder> = createEntityAdapter<Folder>();
export const initialState: FolderState = adapter.getInitialState({
foldersLoaded: false,
foldersLoading: false,
folderDetails: null,
folderDetailsLoaded: false,
folderDetailsLoading: false,
selectedFolder: { name: '', id: '', videosCount: 0}
});
export function reducer(
state = initialState,
action: FolderActions
): FolderState {
switch (action.type) {
case FolderActionTypes.LoadFolders: {
return {
...state,
foldersLoading: true
};
}
示例2: reducer
export interface State extends EntityState<Article> {
selectedArticleId: string | null;
selectedArticle: Article | null;
page: Page | null;
}
export const adapter: EntityAdapter<Article> = createEntityAdapter<Article>({
selectId: (article: Article) => article.id,
sortComparer: false,
});
export const initialState: State = adapter.getInitialState({
selectedArticleId: null,
selectedArticle: null,
page: {
pageSize: 8,
pageIndex: 0,
startIndex: 0,
endIndex: 0
} as Page
});
export function reducer(
state = initialState,
action: ArticlesActions
): State {
switch (action.type) {
case ArticlesActionTypes.LoadArticle: {
return {
...state,
selectedArticleId: state.selectedArticleId,
selectedArticle: null
示例3: reducer
import { HeroActions, HeroActionTypes } from '../actions/hero.actions';
export interface State extends EntityState<Hero> {
loaded: boolean;
loading: boolean;
error: any;
selectedHeroId: number;
searchHeroes: Hero[];
}
export const adapter: EntityAdapter<Hero> = createEntityAdapter<Hero>();
export const initialState: State = adapter.getInitialState({
loaded: false,
loading: false,
selectedHeroId: null,
error: null,
searchTerm: '',
searchHeroes: null
});
export function reducer(state = initialState, action: HeroActions): State {
switch (action.type) {
case HeroActionTypes.heroGetHeroes:
case HeroActionTypes.heroAddHero:
case HeroActionTypes.heroDeleteHero:
case HeroActionTypes.heroUpdateHero:
case HeroActionTypes.heroSearchHeroes:
case HeroActionTypes.heroGetHeroById:
return {
...state,
loading: true
示例4: reducer
import { WidgetActions, WidgetActionTypes } from './widget.actions';
import { Widget } from './widget.model';
export interface State extends EntityState<Widget> {
// additional entities state properties
loaded: boolean;
loading: boolean;
selectedWidgetId: string;
}
export const adapter: EntityAdapter<Widget> = createEntityAdapter<Widget>();
export const initialState: State = adapter.getInitialState({
// additional entity state properties
loaded: false,
loading: false,
selectedWidgetId: '',
});
export function reducer(state = initialState, action: WidgetActions): State {
switch (action.type) {
case WidgetActionTypes.DATABASE_LISTEN_FOR_DATA_STOP: {
return adapter.removeAll({
...state,
loaded: false,
loading: false,
selectedWidgetId: '',
});
}
case WidgetActionTypes.LOAD_SUCCESS: {
示例5: reducer
import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity';
import {createFeatureSelector, createSelector} from '@ngrx/store';
import {Content} from '../../api/model/content';
import * as contentActions from './content.actions';
import * as eventActions from '../event/event.actions';
import * as discussionActions from '../discussion/discussion.actions';
import {Discussion} from '../../api/model/discussion';
export const adapter: EntityAdapter<Content> = createEntityAdapter<Content>();
export interface State extends EntityState<Content> {
}
export const initialState: State = adapter.getInitialState({
});
export function reducer(state = initialState, action: contentActions.Union | eventActions.Union | discussionActions.Union): State {
switch (action.type) {
case contentActions.ActionTypes.CreateContentSuccess: {
return adapter.addOne(action.content, state);
}
case contentActions.ActionTypes.AddManyContentItems: {
return adapter.addMany(action.contents, state);
}
// TODO: move to own reducer
case eventActions.ActionTypes.ParticipateSuccess: {
return adapter.updateOne({id: action.event.contentId, changes: {event: action.event}}, state);
}
示例6: lessonsReducer
if (compare != 0) {
return compare;
}
else {
return l1.seqNo - l2.seqNo;
}
}
export const adapter : EntityAdapter<Lesson> =
createEntityAdapter<Lesson>({
sortComparer: sortByCourseAndSeqNo
});
const initialLessonsState = adapter.getInitialState({
loading: false
});
export function lessonsReducer(state = initialLessonsState,
action: CourseActions): LessonsState {
switch(action.type) {
case CourseActionTypes.LessonsPageCancelled:
return {
...state,
loading:false
};
示例7: reducer
export interface State extends EntityState<Role> {
rolesLoaded: boolean;
rolesLoading: boolean;
availableMembers: RoleMember[];
availableMembersLoaded: boolean;
}
export const adapter: EntityAdapter<Role> = createEntityAdapter<Role>({
selectId: (role: Role) => role.name,
sortComparer: false
});
export const initialState: State = adapter.getInitialState({
rolesLoaded: false,
rolesLoading: false,
availableMembers: [],
availableMembersLoaded: false
});
export function reducer(state = initialState, action: RoleActionsUnion): State {
switch (action.type) {
case RoleActionTypes.GetRoles: {
return {
...state,
rolesLoaded: false,
rolesLoading: true
};
}
case RoleActionTypes.GetRolesSuccess: {
return adapter.addAll(action.payload, {
示例8: reducer
import { Organization } from '../../shared/models';
export interface OrganizationState extends EntityState<Organization> {
entities: { [id: number]: Organization };
organizationsLoading: boolean;
organizationsLoaded: boolean;
}
export const adapter: EntityAdapter<Organization> = createEntityAdapter<
Organization
>();
export const initialState: OrganizationState = adapter.getInitialState({
entities: {},
organizationsLoading: false,
organizationsLoaded: false
});
export function reducer(
state = initialState,
action: fromOrganizations.OrganizationActions
): OrganizationState {
switch (action.type) {
case fromOrganizations.OrganizationActionTypes.LoadOrganizations: {
return {
...state,
organizationsLoading: true
};
}
示例9: reducer
customFields: CustomField[];
customFieldsLoaded: boolean;
customFieldsLoading: boolean;
}
export const adapter: EntityAdapter<VideoListItem> = createEntityAdapter<
VideoListItem
>();
export const initialState: VideoState = adapter.getInitialState({
selectedVideos: [],
videoDetails: null,
videosLoaded: false,
videosLoading: false,
videoDetailsLoaded: false,
videoDetailsLoading: false,
currentFolder: null,
currentPlaylist: null,
customFields: [],
customFieldsLoaded: false,
customFieldsLoading: false
});
export function reducer(
state = initialState,
action: VideoActions
): VideoState {
switch (action.type) {
case VideoActionTypes.LoadVideos: {
return {
...state,
示例10: reducer
sortedBy: string;
categories: any[];
selectedDocuments: number[];
}
export const adapter: EntityAdapter<CandidateListItem> = createEntityAdapter<
CandidateListItem
>();
export const initialState: CandidateState = adapter.getInitialState({
candidatesLoading: false,
candidatesLoaded: false,
candidateDetails: null,
candidateDetailsLoading: false,
candidateDetailsLoaded: false,
orgList: [],
orgFilter: -1,
statusFilter: 'all',
sortedBy: 'date',
categories: [],
selectedDocuments: []
});
export function reducer(
state = initialState,
action: fromCandidate.CandidateActions | fromBoard.BoardActions
): CandidateState {
switch (action.type) {
case fromBoard.BoardActionTypes.LoadBoard: {
return {
...state,
示例11: coursesReducer
export interface CoursesState extends EntityState<Course> {
allCoursesLoaded:boolean;
}
export const adapter : EntityAdapter<Course> =
createEntityAdapter<Course>();
export const initialCoursesState: CoursesState = adapter.getInitialState({
allCoursesLoaded: false
});
export function coursesReducer(state = initialCoursesState , action: CourseActions): CoursesState {
switch(action.type) {
case CourseActionTypes.CourseLoaded:
return adapter.addOne(action.payload.course, state);
case CourseActionTypes.AllCoursesLoaded:
return adapter.addAll(action.payload.courses, {...state, allCoursesLoaded:true});
示例12: reducer
import { VideoActions, VideoActionTypes } from '../actions/video.actions';
export interface PlaylistState extends EntityState<Playlist> {
playlistsLoaded: boolean;
playlistsLoading: boolean;
playlistDetails: PlaylistDetails;
playlistDetailsLoaded: boolean;
playlistDetailsLoading: boolean;
}
export const adapter: EntityAdapter<Playlist> = createEntityAdapter<Playlist>();
export const initialState: PlaylistState = adapter.getInitialState({
playlistsLoaded: false,
playlistsLoading: false,
playlistDetails: null,
playlistDetailsLoaded: false,
playlistDetailsLoading: false
});
export function reducer(
state = initialState,
action: PlaylistsAction | VideoActions
): PlaylistState {
switch (action.type) {
case PlaylistActionTypes.LoadPlaylists: {
return {
...state,
playlistsLoading: true
};
}
示例13: reducer
import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity';
import { Panel } from '../models';
import { PanelActionsUnion, PanelActionTypes } from './panels.actions';
export interface State extends EntityState<Panel> {
panelsLoading: boolean;
panelMemberReport: any;
}
export const adapter: EntityAdapter<Panel> = createEntityAdapter<Panel>();
export const initialState: State = adapter.getInitialState({
panelsLoading: false,
panelMemberReport: null
});
export function reducer(
state = initialState,
action: PanelActionsUnion
): State {
switch (action.type) {
case PanelActionTypes.GetPanels: {
return {
...state,
panelsLoading: true
};
}
case PanelActionTypes.PanelsReceived: {
return adapter.addAll(action.payload, {
示例14: reducer
* object takes a record id selector function and
* a sortComparer option which is set to a compare
* function if the records are to be sorted.
*/
export const adapter: EntityAdapter<Book> = createEntityAdapter<Book>({
selectId: (book: Book) => book.id,
sortComparer: false,
});
/**
* getInitialState returns the default initial state
* for the generated entity state. Initial state
* additional properties can also be defined.
*/
export const initialState: State = adapter.getInitialState({
selectedBookId: null,
});
export function reducer(
state = initialState,
action:
| BooksApiActions.BooksApiActionsUnion
| BookActions.BookActionsUnion
| ViewBookPageActions.ViewBookPageActionsUnion
| CollectionApiActions.CollectionApiActionsUnion
): State {
switch (action.type) {
case BooksApiActions.BooksApiActionTypes.SearchSuccess:
case CollectionApiActions.CollectionApiActionTypes.LoadBooksSuccess: {
/**
* The addMany function provided by the created adapter
示例15: reducer
// entities: { [id: number]: PanelListItem };
panelsLoaded: boolean;
panelsLoading: boolean;
panelDetails: PanelDetails;
panelDetailsLoading: boolean;
panelDetailsLoaded: boolean;
}
export const adapter: EntityAdapter<PanelListItem> = createEntityAdapter<
PanelListItem
>();
export const initialState: PanelState = adapter.getInitialState({
//entities: {},
panelsLoaded: false,
panelsLoading: false,
panelDetails: null,
panelDetailsLoaded: false,
panelDetailsLoading: false
});
export function reducer(
state = initialState,
action: PanelActions
): PanelState {
switch (action.type) {
case PanelActionTypes.LoadPanels: {
return {
...state,
panelsLoading: true
};
}