"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _data = require("../actions/data");

var _collection = _interopRequireDefault(require("./collection"));

var _redux = require("redux");

/*
 * Copyright (C) 2018 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
// binds a collection reducer to listen only to actions directed at it
function boundCollectionReducer(key) {
  return function () {
    var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    var action = arguments.length > 1 ? arguments[1] : undefined;

    switch (action.type) {
      case _data.REQUEST_PAGE:
      case _data.RECEIVE_PAGE:
      case _data.FAIL_PAGE:
        if (action.key === key) {
          return (0, _collection.default)(state, action);
        } else {
          return state;
        }

      default:
        return state;
    }
  };
} // combine a collection reducer for each collection we care about


var _default = (0, _redux.combineReducers)({
  announcements: boundCollectionReducer("announcements"),
  assignments: boundCollectionReducer("assignments"),
  discussions: boundCollectionReducer("discussions"),
  modules: boundCollectionReducer("modules"),
  quizzes: boundCollectionReducer("quizzes"),
  wikiPages: boundCollectionReducer("wikiPages")
});

exports.default = _default;