• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript entity.createEntityAdapter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@ngrx/entity.createEntityAdapter函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createEntityAdapter函数的具体用法?TypeScript createEntityAdapter怎么用?TypeScript createEntityAdapter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了createEntityAdapter函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: Error

export function createEntityDefinition<T, S extends object>(metadata: EntityMetadata<T, S>): EntityDefinition<T> {
  let entityName = metadata.entityName;
  if (!entityName) {
    throw new Error('Missing required entityName');
  }
  metadata.entityName = entityName = entityName.trim();
  const selectId = metadata.selectId || defaultSelectId;
  const sortComparer = (metadata.sortComparer = metadata.sortComparer || false);

  const entityAdapter = createEntityAdapter<T>({ selectId, sortComparer });

  const entityDispatcherOptions: Partial<EntityDispatcherDefaultOptions> = metadata.entityDispatcherOptions || {};

  const initialState: EntityCollection<T> = entityAdapter.getInitialState({
    entityName,
    filter: '',
    loaded: false,
    loading: false,
    changeState: {},
    ...(metadata.additionalCollectionState || {})
  });

  const noChangeTracking = metadata.noChangeTracking === true; // false by default

  return {
    entityName,
    entityAdapter,
    entityDispatcherOptions,
    initialState,
    metadata,
    noChangeTracking,
    selectId,
    sortComparer
  };
}
开发者ID:RajeevSingh273,项目名称:angular-ngrx-data,代码行数:35,代码来源:entity-definition.ts


示例2: reducer

import { PanelActions, PanelActionTypes } from '../actions/panel.actions';

import { PanelDetails, PanelListItem } from '../../shared/models';

export interface PanelState extends EntityState<PanelListItem> {
//  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 {
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:30,代码来源:panel.reducer.ts


示例3: reducer

import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity';

import * as fromOrganizations from '../actions/organization.actions';

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
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:31,代码来源:organization.reducer.ts


示例4: switch

import { createEntityAdapter } from '@ngrx/entity';
import { State } from '@ngrx/store';
import { ActionReducer } from '@ngrx/store';
import * as LabelActions  from './../actions/label.actions';
import { LabelUI } from './../models/label.model';
import { initialState, LabelState } from './../states/label.state';

export type Action = LabelActions.All;
const labelAdapter = createEntityAdapter<LabelUI>();

export const LabelReducer: ActionReducer<LabelState> = (state = initialState, action: Action) => {
  switch (action.type) {
    case LabelActions.GET_SUCCESS: {
      return labelAdapter.addAll(action.payload, state);
    }
    case LabelActions.GET_ERROR: {
      return state;
    }
    case LabelActions.ADD_SUCCESS: {
      return labelAdapter.addOne(action.payload, state);
    }
    case LabelActions.ADD_ERROR: {
      return state;
    }
    default: {
      return state;
    }
  }
};
开发者ID:joshuawilson,项目名称:almighty-ui,代码行数:29,代码来源:label.reducer.ts


示例5: reducer

import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';

import { Article, Page } from '../../shared/models';
import { ArticlesActions, ArticlesActionTypes } from '../actions/articles';

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 {
开发者ID:evcraddock,项目名称:erikvancraddock.com,代码行数:31,代码来源:articles.ts


示例6: reducer

import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity';

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: '',
      });
    }
开发者ID:tja4472,项目名称:ngrx-ionic-angularfire,代码行数:31,代码来源:widget.reducer.ts


示例7: reducer

  EntityState,
  Update
} from '@ngrx/entity';

import { Hero } from '../../models/hero';
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:
开发者ID:klimentru1986,项目名称:ngrx-toh,代码行数:31,代码来源:hero.reducer.ts


示例8: sortByCourseAndSeqNo

  loading:boolean;
}

function sortByCourseAndSeqNo(l1: Lesson, l2:Lesson) {
  const compare = l1.courseId - l2.courseId;
  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:
开发者ID:mrplanktonlex,项目名称:angular-ngrx-course,代码行数:31,代码来源:lessons.reducers.ts


示例9: coursesReducer

import {Course} from './model/course';
import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity';
import {CourseActions, CourseActionTypes} from './course.actions';



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:
开发者ID:mrplanktonlex,项目名称:angular-ngrx-course,代码行数:31,代码来源:course.reducers.ts


示例10: reducer

import {
  PlaylistActionTypes,
  PlaylistsAction
} from '../actions/playlist.actions';

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: {
开发者ID:ArmyMusicOnline,项目名称:ami,代码行数:31,代码来源:playlist.reducer.ts



注:本文中的@ngrx/entity.createEntityAdapter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript entity.EntityAdapter类代码示例发布时间:2022-05-28
下一篇:
TypeScript testing.MockStateUpdates类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap