UNPKG

mattermost-redux

Version:

Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client

45 lines 3.12 kB
"use strict"; // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var redux = tslib_1.__importStar(require("redux")); var reducer_registry_1 = tslib_1.__importDefault(require("./reducer_registry")); var reducers_1 = tslib_1.__importDefault(require("../reducers")); var helpers_1 = require("./helpers"); var initial_state_1 = tslib_1.__importDefault(require("./initial_state")); var middleware_1 = require("./middleware"); var redux_offline_1 = require("redux-offline"); var defaults_1 = tslib_1.__importDefault(require("redux-offline/lib/defaults")); /** * Configures and constructs the redux store. Accepts the following parameters: * preloadedState - Any preloaded state to be applied to the store after it is initially configured. * appReducer - An object containing any app-specific reducer functions that the client needs. * userOfflineConfig - Any additional configuration data to be passed into redux-offline aside from the default values. * getAppReducer - A function that returns the appReducer as defined above. Only used in development to enable hot reloading. * clientOptions - An object containing additional options used when configuring the redux store. The following options are available: * additionalMiddleware - func | array - Allows for single or multiple additional middleware functions to be passed in from the client side. * enableBuffer - bool - default = true - If true, the store will buffer all actions until offline state rehydration occurs. * enableThunk - bool - default = true - If true, include the thunk middleware automatically. If false, thunk must be provided as part of additionalMiddleware. */ function configureOfflineServiceStore(preloadedState, appReducer, userOfflineConfig, getAppReducer, clientOptions) { if (clientOptions === void 0) { clientOptions = {}; } var baseState = Object.assign({}, initial_state_1.default, preloadedState); var baseOfflineConfig = Object.assign({}, defaults_1.default, helpers_1.offlineConfig, userOfflineConfig); var store = redux.createStore(redux_offline_1.createOfflineReducer(helpers_1.createReducer(baseState, reducers_1.default, appReducer)), baseState, redux_offline_1.offlineCompose(baseOfflineConfig)(middleware_1.createMiddleware(clientOptions), [])); reducer_registry_1.default.setChangeListener(function (reducers) { store.replaceReducer(redux_offline_1.createOfflineReducer(helpers_1.createReducer(baseState, reducers))); }); // launch store persistor if (baseOfflineConfig.persist) { baseOfflineConfig.persist(store, baseOfflineConfig.persistOptions, baseOfflineConfig.persistCallback); } if (baseOfflineConfig.detectNetwork) { baseOfflineConfig.detectNetwork(function (online) { store.dispatch(redux_offline_1.networkStatusChangedAction(online)); }); } return store; } exports.default = configureOfflineServiceStore; //# sourceMappingURL=configureStore.prod.js.map