當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript EntityAdapter.addMany方法代碼示例

本文整理匯總了TypeScript中@ngrx/entity.EntityAdapter.addMany方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EntityAdapter.addMany方法的具體用法?TypeScript EntityAdapter.addMany怎麽用?TypeScript EntityAdapter.addMany使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ngrx/entity.EntityAdapter的用法示例。


在下文中一共展示了EntityAdapter.addMany方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: lessonsReducer

export function lessonsReducer(state = initialLessonsState,
                               action: CourseActions): LessonsState {

  switch(action.type) {

    case CourseActionTypes.LessonsPageCancelled:

      return {
        ...state,
        loading:false
      };

    case CourseActionTypes.LessonsPageRequested:
      return {
        ...state,
        loading:true
      };

    case CourseActionTypes.LessonsPageLoaded:

      return adapter.addMany(action.payload.lessons, {...state, loading:false});


    default:

      return state;

  }

}
開發者ID:mrplanktonlex,項目名稱:angular-ngrx-course,代碼行數:30,代碼來源:lessons.reducers.ts

示例2: reducer

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);
    }

    case eventActions.ActionTypes.UnparticipateSuccess: {
      return adapter.updateOne({id: action.event.contentId, changes: {event: action.event}}, state);
    }

    case discussionActions.ActionTypes.CreateCommentSuccess: {
      const discussion = {...state.entities[action.contentId].discussion} as Discussion;
      discussion.comments = discussion.comments.concat(action.comment);

      return adapter.updateOne({id: action.contentId, changes: {discussion}}, state);
    }
  }

  return state;
}
開發者ID:arner,項目名稱:saevis,代碼行數:29,代碼來源:content.reducer.ts

示例3: reducer

export function reducer(state = initialState, action: topicsActions.Union): State {
  switch (action.type) {
    case topicsActions.ActionTypes.FetchTopicsSuccess: {
      return adapter.addMany(action.topics, state);
    }

    // case TopicsActions.ActionTypes.AddNormalizedTopics: {
    //   return adapter.addMany(action.topics, state);
    // }
    // case topicsActions.ActionTypes.AddContentRefToTopic: {
    //   const topic = {...state.entities[action.topicId]} as any;
    //
    //   return adapter.updateOne({id: action.topicId, changes: {content: topic.content.concat(action.contentId)}}, state);
    // }

    case topicsActions.ActionTypes.FetchTopicSuccess: {
      return adapter.addOne(action.topic, state);
    }

    case topicsActions.ActionTypes.CreateTopicSuccess: {
      return adapter.addOne(action.topic, state);
    }
  }

  return state;
}
開發者ID:arner,項目名稱:saevis,代碼行數:26,代碼來源:topics.reducer.ts

示例4: reducer

export function reducer(state = initialState, action: BookActions | CollectionActions) {
  switch (action.type) {
    case BookActionTypes.SearchComplete:
    case CollectionActionTypes.LoadSuccess: {
      return {
        /**
         * 將許多記錄添加到實體字典,並返回一個新的狀態,包括那些記錄。
         * 如果要對集合進行排序,則適配器將在進入已排序的數組時對每個記錄進行排序。
         */
        ...adapter.addMany(action.payload, state),
        selectedBookId: state.selectedBookId
      };
    }
    case BookActionTypes.Load: {
      return {
        /**
         * 將一個記錄添加到實體字典,並返回一個新的狀態,包括該記錄如果不存在的話。
         * 如果要對集合進行排序,則適配器將把新記錄插入到已排序的數組中。
         */
        ...adapter.addOne(action.payload, state),
        selectedBookId: state.selectedBookId
      };
    }
    case BookActionTypes.Select: {
      return {
        ...state,
        selectedBookId: action.payload
      };
    }
    default: {
      return state;
    }
  }
}
開發者ID:tensen100,項目名稱:myNgrx,代碼行數:34,代碼來源:books.reducers.ts

示例5: reducer

export function reducer(
  state = initialState,
  action: BookActionsUnion | CollectionActionsUnion
): State {
  switch (action.type) {
    case BookActionTypes.SearchComplete:
    case CollectionActionTypes.LoadSuccess: {
      /**
       * The addMany function provided by the created adapter
       * adds many records to the entity dictionary
       * and returns a new state including those records. If
       * the collection is to be sorted, the adapter will
       * sort each record upon entry into the sorted array.
       */
      return adapter.addMany(action.payload, {
        ...state,
        selectedBookId: state.selectedBookId,
      });
    }

    case BookActionTypes.Load: {
      /**
       * The addOne function provided by the created adapter
       * adds one record to the entity dictionary
       * and returns a new state including that records if it doesn't
       * exist already. If the collection is to be sorted, the adapter will
       * insert the new record into the sorted array.
       */
      return adapter.addOne(action.payload, {
        ...state,
        selectedBookId: state.selectedBookId,
      });
    }

    case BookActionTypes.Select: {
      return {
        ...state,
        selectedBookId: action.payload,
      };
    }

    default: {
      return state;
    }
  }
}
開發者ID:AlexChar,項目名稱:platform,代碼行數:46,代碼來源:books.reducer.ts

示例6: reducer

export function reducer(
  state = initialState,
  action: book.Actions
): State {
  switch (action.type) {
    case book.SEARCH_COMPLETE: {
      return {
        /**
         * The addMany function provided by the created adapter
         * adds many records to the entity dictionary
         * and returns a new state including those records. If
         * the collection is to be sorted, the adapter will
         * sort each record upon entry into the sorted array.
         */
        ...adapter.addMany(action.payload, state),
        selectedBookId: state.selectedBookId,
      };
    }

    case book.LOAD: {
      return {
        /**
         * The addOne function provided by the created adapter
         * adds one record to the entity dictionary
         * and returns a new state including that records if it doesn't
         * exist already. If the collection is to be sorted, the adapter will
         * insert the new record into the sorted array.
         */
        ...adapter.addOne(action.payload, state),
        selectedBookId: state.selectedBookId,
      };
    }

    case book.SELECT: {
      return {
        ...state,
        selectedBookId: action.payload,
      };
    }

    default: {
      return state;
    }
  }
}
開發者ID:knarfeh,項目名稱:eebookorg,代碼行數:45,代碼來源:books.ts

示例7: reducer

export function reducer(
    state = initialState,
    action: ArticlesActions
): State {
    switch (action.type) {
        case ArticlesActionTypes.LoadArticle: {
            return {
                ...state,
                selectedArticleId: state.selectedArticleId,
                selectedArticle: null
            };
        }

        case ArticlesActionTypes.Load: {
            return adapter.removeAll({
                ...state,
            });
        }

        case ArticlesActionTypes.LoadSuccess: {
            return adapter.addMany(action.payload.articles, {
                ...state,
                selectedArticleId: null,
                selectedArticle: null,
            } as State);
        }

        case ArticlesActionTypes.LoadFail: {
            return Object.assign({}, {
                ...state
            } as State);
        }

        case ArticlesActionTypes.ChangePage: {
            const index = action.payload;
            const start = index * state.page.pageSize;

            return {
                ...state,
                page: {
                    pageIndex: index,
                    pageSize: state.page.pageSize,
                    startIndex: start,
                    endIndex: start + state.page.pageSize
                } as Page
            };
        }

        case ArticlesActionTypes.SelectArticle: {
            return {
                ...state,
                selectedArticleId: action.payload,
                selectedArticle: null
            };
        }

        case ArticlesActionTypes.SelectArticleSuccess: {
            return {
                ...state,
                selectedArticleId: state.selectedArticleId,
                selectedArticle: action.payload.article
            };
        }

        case ArticlesActionTypes.SelectArticleFail: {
            return {
                ...state
            };
        }

        default: {
            return state;
        }
    }
}
開發者ID:evcraddock,項目名稱:erikvancraddock.com,代碼行數:75,代碼來源:articles.ts

示例8: reducer

export function reducer(state = initialState, action: GizmoActions): State {
  switch (action.type) {
    case GizmoActionTypes.DATABASE_LISTEN_FOR_DATA_START: {
      return {
        ...state,
        loading: true,
      };
    }

    case GizmoActionTypes.DATABASE_LISTEN_FOR_DATA_STOP: {
      return adapter.removeAll({
        ...state,
        loaded: false,
        loading: false,
        selectedGizmoId: '',
      });
    }

    /*
    case GizmoActionTypes.ADD_GIZMO: {
      return adapter.addOne(action.payload.gizmo, state);
    }

    case GizmoActionTypes.ADD_GIZMOS: {
      return adapter.addMany(action.payload.gizmos, state);
    }

    case GizmoActionTypes.UPDATE_GIZMO: {
      return adapter.updateOne(action.payload.gizmo, state);
    }
*/
    case GizmoActionTypes.STORE_ADD_ITEMS: {
      return {
        ...adapter.addMany(action.payload.gizmos, state),
        loaded: true,
        loading: false,
      };
    }

    case GizmoActionTypes.STORE_DELETE_ITEMS: {
      return adapter.removeMany(action.payload.ids, state);
    }

    case GizmoActionTypes.STORE_UPDATE_ITEMS: {
      return adapter.updateMany(action.payload.items, state);
    }
    /*
    case GizmoActionTypes.DELETE_GIZMO: {
      return adapter.removeOne(action.payload.id, state);
    }

    case GizmoActionTypes.LOAD_GIZMOS: {
      return adapter.addAll(action.payload.gizmos, state);
    }

    case GizmoActionTypes.CLEAR_GIZMOS: {
      return adapter.removeAll({ ...state, selectedGizmoId: '' });
    }
*/
    default: {
      return state;
    }
  }
}
開發者ID:tja4472,項目名稱:ngrx-ionic-angularfire,代碼行數:64,代碼來源:gizmo.reducer.ts


注:本文中的@ngrx/entity.EntityAdapter.addMany方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。