How to use @ngrx/entity - 10 common examples

To help you get started, we’ve selected a few @ngrx/entity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fabric8-ui / fabric8-ui / packages / planner / src / app / models / work-item.ts View on Github external
columnIds?: string[] | null;

  treeStatus: 'collapsed' | 'expanded' | 'disabled' | 'loading'; // collapsed
  childrenLoaded: boolean; // false
  bold: boolean; // false

  createId?: number; // this is used to identify newly created item
  selected: boolean;
  editable?: boolean; // Based on the logged in user this value will be changed. Default value is false
}

export interface WorkItemStateModel extends EntityState {
  nextLink: string;
}

const workItemAdapter = createEntityAdapter();
const { selectIds, selectEntities, selectAll, selectTotal } = workItemAdapter.getSelectors();

export class WorkItemMapper implements Mapper {
  wiTypeMapper = new WorkItemTypeMapper();
  labelMapper = new LabelMapper();
  serviceToUiMapTree: MapTree = [
    {
      fromPath: ['id'],
      toPath: ['id'],
    },
    {
      fromPath: ['attributes', 'system.title'],
      toPath: ['title'],
    },
    {
      fromPath: ['attributes', 'system.number'],
github johannesjo / super-productivity / src / app / issue / jira / jira-issue / store / jira-issue.reducer.ts View on Github external
import { createEntityAdapter, EntityAdapter, EntityState } from '@ngrx/entity';
import { JiraIssueActions, JiraIssueActionTypes } from './jira-issue.actions';
import { JiraIssue } from '../jira-issue.model';
import { createFeatureSelector, createSelector } from '@ngrx/store';
import { TaskActionTypes } from '../../../../tasks/store/task.actions';

export const JIRA_ISSUE_FEATURE_NAME = 'issues';

export interface JiraIssueState extends EntityState {
  // additional entities state properties
  currentJiraIssueId: string | null;
}

export const jiraIssueAdapter: EntityAdapter = createEntityAdapter();


// SELECTORS
// ---------
export const selectJiraIssueFeatureState = createFeatureSelector(JIRA_ISSUE_FEATURE_NAME);

const {selectIds, selectEntities, selectAll, selectTotal} = jiraIssueAdapter.getSelectors();

export const selectJiraIssueIds = createSelector(selectJiraIssueFeatureState, selectIds);
export const selectJiraIssueEntities = createSelector(selectJiraIssueFeatureState, selectEntities);
export const selectAllJiraIssues = createSelector(selectJiraIssueFeatureState, selectAll);

// select the total user count
export const selectJiraIssueTotal = createSelector(selectJiraIssueFeatureState, selectTotal);

export const selectCurrentJiraIssue = createSelector(selectJiraIssueFeatureState, state => state.currentJiraIssueId);
github johannesjo / super-productivity / src / app / features / bookmark / store / bookmark.reducer.ts View on Github external
import {createEntityAdapter, EntityAdapter, EntityState} from '@ngrx/entity';
import {BookmarkActions, BookmarkActionTypes} from './bookmark.actions';
import {Bookmark} from '../bookmark.model';
import {createFeatureSelector, createSelector} from '@ngrx/store';

export const BOOKMARK_FEATURE_NAME = 'bookmark';

export interface BookmarkState extends EntityState {
  // additional entities state properties
  isShowBookmarks: boolean;
}

export const adapter: EntityAdapter = createEntityAdapter();
export const selectBookmarkFeatureState = createFeatureSelector(BOOKMARK_FEATURE_NAME);
export const {selectIds, selectEntities, selectAll, selectTotal} = adapter.getSelectors();
export const selectAllBookmarks = createSelector(selectBookmarkFeatureState, selectAll);
export const selectIsShowBookmarkBar = createSelector(selectBookmarkFeatureState, state => state.isShowBookmarks);

export const initialBookmarkState: BookmarkState = adapter.getInitialState({
  // additional entity state properties
  isShowBookmarks: false
});

export function bookmarkReducer(
  state = initialBookmarkState,
  action: BookmarkActions
): BookmarkState {
  switch (action.type) {
    case BookmarkActionTypes.AddBookmark: {
github angular-university / ngrx-course / src / app / courses / reducers / course.reducers.ts View on Github external
import {compareCourses, Course} from '../model/course';
import {createEntityAdapter, EntityState} from '@ngrx/entity';
import {createReducer, on} from '@ngrx/store';
import {CourseActions} from '../action-types';


export interface CoursesState extends EntityState {
    allCoursesLoaded: boolean
}


export const adapter = createEntityAdapter({
    sortComparer: compareCourses
});


export const initialCoursesState = adapter.getInitialState({
    allCoursesLoaded:false
});


export const coursesReducer = createReducer(

    initialCoursesState,

    on(CourseActions.allCoursesLoaded,
        (state, action) => adapter.addAll(
            action.courses,
github bwsw / cloudstack-ui / src / app / reducers / roles / redux / roles.reducers.ts View on Github external
list: State;
}

export const roleReducers = {
  list: reducer,
};

/**
 * createEntityAdapter creates many an object of helper
 * functions for single or multiple operations
 * against the dictionary of records. The configuration
 * 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 = createEntityAdapter({
  selectId: (item: Role) => item.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({
  loading: false,
});

export function reducer(state = initialState, action: event.Actions): State {
  switch (action.type) {
    case event.LOAD_ROLES_REQUEST: {
      return {
github bwsw / cloudstack-ui / src / app / reducers / account-tags / redux / account-tags.reducers.ts View on Github external
list: State;
}

export const accountTagsReducers = {
  list: reducer,
};

/**
 * createEntityAdapter creates many an object of helper
 * functions for single or multiple operations
 * against the dictionary of records. The configuration
 * 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 = createEntityAdapter({
  selectId: (item: Tag) => item.key,
  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({
  loading: false,
  loaded: false,
});

export function reducer(state = initialState, action: accountTagActions.Actions): State {
  switch (action.type) {
    case accountTagActions.LOAD_ACCOUNT_TAGS_REQUEST: {
github ngrx-utils / ngrx-utils / example-app / app / books / reducers / books.ts View on Github external
* model type by id. This interface is extended to include
 * any additional interface properties.
 */
export interface State extends EntityState {
  selectedBookId: string | null;
}

/**
 * createEntityAdapter creates many an object of helper
 * functions for single or multiple operations
 * against the dictionary of records. The configuration
 * 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 = createEntityAdapter({
  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: BookActions | CollectionActions): State {
  switch (action.type) {
    case BookActionTypes.SearchComplete:
github chef / automate / components / automate-ui / src / app / entities / roles / role.reducer.ts View on Github external
import { EntityState, EntityAdapter, createEntityAdapter } from '@ngrx/entity';
import { set } from 'lodash/fp';

import { EntityStatus } from 'app/entities/entities';
import { RoleActionTypes, RoleActions } from './role.actions';
import { Role } from './role.model';

export interface RoleEntityState extends EntityState {
  getAllStatus: EntityStatus;
  getStatus: EntityStatus;
  deleteStatus: EntityStatus;
}

export const roleEntityAdapter: EntityAdapter = createEntityAdapter();

export const RoleEntityInitialState: RoleEntityState = roleEntityAdapter.getInitialState({
  getAllStatus: EntityStatus.notLoaded,
  getStatus: EntityStatus.notLoaded,
  deleteStatus: EntityStatus.notLoaded
});

export function roleEntityReducer(state: RoleEntityState = RoleEntityInitialState,
  action: RoleActions) {

  switch (action.type) {
    case RoleActionTypes.GET_ALL:
      return set('getAllStatus', EntityStatus.loading, roleEntityAdapter.removeAll(state));

    case RoleActionTypes.GET_ALL_SUCCESS:
      return set('getAllStatus', EntityStatus.loadingSuccess,
github Lumeer / web-ui / src / app / core / store / pivots / pivots.state.ts View on Github external
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

import {createSelector} from '@ngrx/store';
import {AppState} from '../app.state';
import {createEntityAdapter, EntityState} from '@ngrx/entity';
import {DEFAULT_PIVOT_ID, Pivot} from './pivot';

export interface PivotsState extends EntityState {}

export const pivotsAdapter = createEntityAdapter({selectId: pivot => pivot.id});

export const initialPivotsState: PivotsState = pivotsAdapter.getInitialState();

export const selectPivotsState = (state: AppState) => state.pivots;
export const selectPivotsDictionary = createSelector(
  selectPivotsState,
  pivotsAdapter.getSelectors().selectEntities
);
export const selectPivotById = id =>
  createSelector(
    selectPivotsDictionary,
    pivots => pivots[id]
  );

export const selectDefaultPivot = selectPivotById(DEFAULT_PIVOT_ID);
export const selectPivotConfig = createSelector(
github bwsw / cloudstack-ui / src / app / reducers / disk-offerings / redux / disk-offerings.reducers.ts View on Github external
import * as fromVMs from '../../vm/redux/vm.reducers';
import { isTemplate } from '../../../template/shared';

export interface State extends EntityState {
  loading: boolean;
}

export interface OfferingsState {
  list: State;
}

export const diskOfferingReducers = {
  list: reducer,
};

export const adapter: EntityAdapter = createEntityAdapter({
  selectId: (item: DiskOffering) => item.id,
  sortComparer: false,
});

export const initialState: State = adapter.getInitialState({
  loading: false,
});

export function reducer(state = initialState, action: event.Actions): State {
  switch (action.type) {
    case event.LOAD_DISK_OFFERINGS_REQUEST: {
      return {
        ...state,
        loading: true,
      };
    }

@ngrx/entity

Common utilities for entity reducers

MIT
Latest version published 6 days ago

Package Health Score

98 / 100
Full package analysis

Popular @ngrx/entity functions