Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #57 from mattermost/initial-state
Browse files Browse the repository at this point in the history
Add initial state directly into service layer
  • Loading branch information
jwilander authored and hmhealey committed Aug 28, 2020
1 parent 1f9754a commit 71a4ca0
Show file tree
Hide file tree
Showing 7 changed files with 437 additions and 8 deletions.
5 changes: 4 additions & 1 deletion packages/mattermost-redux/.babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"presets": ["react-native"],
"presets": [
"es2015",
"stage-0"
],
"plugins": [
["module-resolver", {
"root": ["./src", "."]
Expand Down
3 changes: 2 additions & 1 deletion packages/mattermost-redux/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"babel-cli": "6.24.0",
"babel-eslint": "7.2.1",
"babel-plugin-module-resolver": "2.7.0",
"babel-preset-es2015": "6.24.0",
"babel-preset-stage-0": "6.22.0",
"babel-polyfill": "6.23.0",
"babel-preset-react-native": "1.9.1",
"babel-register": "6.24.0",
"chai": "3.5.0",
"deep-freeze": "0.0.1",
Expand Down
8 changes: 6 additions & 2 deletions packages/mattermost-redux/src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,28 @@ export default class Client {
}

getOptions(options) {
const newOptions = Object.assign({}, options);

const headers = {
[HEADER_REQUESTED_WITH]: 'XMLHttpRequest'
};

if (this.token) {
headers[HEADER_AUTH] = `${HEADER_BEARER} ${this.token}`;
} else {
newOptions.credentials = 'include';
}

if (this.userAgent) {
headers[HEADER_USER_AGENT] = this.userAgent;
}

if (options.headers) {
Object.assign(headers, options.headers);
Object.assign(headers, newOptions.headers);
}

return {
...options,
...newOptions,
headers
};
}
Expand Down
8 changes: 6 additions & 2 deletions packages/mattermost-redux/src/client/client4.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,28 @@ export default class Client4 {
}

getOptions(options) {
const newOptions = Object.assign({}, options);

const headers = {
[HEADER_REQUESTED_WITH]: 'XMLHttpRequest'
};

if (this.token) {
headers[HEADER_AUTH] = `${HEADER_BEARER} ${this.token}`;
} else {
newOptions.credentials = 'include';
}

if (this.userAgent) {
headers[HEADER_USER_AGENT] = this.userAgent;
}

if (options.headers) {
Object.assign(headers, options.headers);
Object.assign(headers, newOptions.headers);
}

return {
...options,
...newOptions,
headers
};
}
Expand Down
5 changes: 4 additions & 1 deletion packages/mattermost-redux/src/store/configureStore.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import createActionBuffer from 'redux-action-buffer';
import {General} from 'constants';
import serviceReducer from 'reducers';
import deepFreezeAndThrowOnMutation from 'utils/deep_freeze';
import initialState from './initial_state';

export default function configureServiceStore(preloadedState, appReducer, getAppReducer) {
const baseState = Object.assign({}, initialState, preloadedState);

const store = createStore(
createReducer(serviceReducer, appReducer),
preloadedState,
baseState,
compose(
applyMiddleware(thunk),
devTools({
Expand Down
4 changes: 3 additions & 1 deletion packages/mattermost-redux/src/store/configureStore.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import createActionBuffer from 'redux-action-buffer';

import {General} from 'constants';
import serviceReducer from 'reducers';
import initialState from './initial_state';

export default function configureServiceStore(preloadedState, appReducer) {
const baseReducer = combineReducers(Object.assign({}, serviceReducer, appReducer));
const baseState = Object.assign({}, initialState, preloadedState);
return createStore(
enableBatching(baseReducer),
preloadedState,
baseState,
applyMiddleware(thunk)
);
}
Expand Down
Loading

0 comments on commit 71a4ca0

Please sign in to comment.