Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Inject Redux store to prevent/remove require cycles #3691

Merged
merged 7 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/containers/MessageBox/EmojiKeyboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { View } from 'react-native';
import { KeyboardRegistry } from 'react-native-ui-lib/keyboard';

import store from '../../lib/createStore';
import { store } from '../../lib/auxStore';
import EmojiPicker from '../EmojiPicker';
import styles from './styles';
import { themes } from '../../constants/colors';
Expand Down
2 changes: 1 addition & 1 deletion app/ee/omnichannel/lib/subscriptions/inquiry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import log from '../../../../utils/log';
import store from '../../../../lib/createStore';
import { store } from '../../../../lib/auxStore';
import RocketChat from '../../../../lib/rocketchat';
import { inquiryQueueAdd, inquiryQueueRemove, inquiryQueueUpdate, inquiryRequest } from '../../actions/inquiry';

Expand Down
2 changes: 2 additions & 0 deletions app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ import debounce from './utils/debounce';
import { isFDroidBuild } from './constants/environment';
import { IThemePreference } from './definitions/ITheme';
import { ICommand } from './definitions/ICommand';
import { initStore } from './lib/auxStore';

RNScreens.enableScreens();
initStore(store);

interface IDimensions {
width: number;
Expand Down
10 changes: 10 additions & 0 deletions app/lib/auxStore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Store } from 'redux';

import { IApplicationState } from '../definitions';

// https://redux.js.org/faq/code-structure#how-can-i-use-the-redux-store-in-non-component-files
export let store: Store<IApplicationState> = null as any;

export const initStore = (_store: Store): void => {
store = _store;
};
2 changes: 1 addition & 1 deletion app/lib/encryption/encryption.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import database from '../database';
import protectedFunction from '../methods/helpers/protectedFunction';
import Deferred from '../../utils/deferred';
import log from '../../utils/log';
import store from '../createStore';
import { store } from '../auxStore';
import {
E2E_BANNER_TYPE,
E2E_MESSAGE_TYPE,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/callJitsi.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import Navigation from '../Navigation';
import { events, logEvent } from '../../utils/log';

Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/canOpenRoom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import database from '../database';
import store from '../createStore';
import { store } from '../auxStore';

const restTypes = {
channel: 'channels',
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/enterpriseModules.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { compareServerVersion } from '../utils';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import database from '../database';
import log from '../../utils/log';
import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getCustomEmojis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import orderBy from 'lodash/orderBy';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';

import { compareServerVersion } from '../utils';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import database from '../database';
import log from '../../utils/log';
import { setCustomEmojis as setCustomEmojisAction } from '../../actions/customEmojis';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import orderBy from 'lodash/orderBy';
import { compareServerVersion } from '../utils';
import database from '../database';
import log from '../../utils/log';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import RocketChat from '../rocketchat';
import { setPermissions as setPermissionsAction } from '../../actions/permissions';
import protectedFunction from './helpers/protectedFunction';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';

import database from '../database';
import log from '../../utils/log';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import { removeRoles, setRoles as setRolesAction, updateRoles } from '../../actions/roles';
import protectedFunction from './helpers/protectedFunction';

Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Q } from '@nozbe/watermelondb';

import { addSettings, clearSettings } from '../../actions/settings';
import RocketChat from '../rocketchat';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import settings from '../../constants/settings';
import log from '../../utils/log';
import database from '../database';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/getUsersPresence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { InteractionManager } from 'react-native';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';

import { compareServerVersion } from '../utils';
import reduxStore from '../createStore';
import { store as reduxStore } from '../auxStore';
import { setActiveUsers } from '../../actions/activeUsers';
import { setUser } from '../../actions/login';
import database from '../database';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/helpers/mergeSubscriptionsRooms.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EJSON from 'ejson';

import { Encryption } from '../../encryption';
import reduxStore from '../../createStore';
import { store as reduxStore } from '../../auxStore';
import { compareServerVersion } from '../../utils';
import findSubscriptionsRooms from './findSubscriptionsRooms';
import normalizeMessage from './normalizeMessage';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/subscriptions/rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import protectedFunction from '../helpers/protectedFunction';
import messagesStatus from '../../../constants/messagesStatus';
import log from '../../../utils/log';
import random from '../../../utils/random';
import store from '../../createStore';
import { store } from '../../auxStore';
import { handlePayloadUserInteraction } from '../actions';
import buildMessage from '../helpers/buildMessage';
import RocketChat from '../../rocketchat';
Expand Down
2 changes: 1 addition & 1 deletion app/lib/rocketchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { updatePermission } from '../actions/permissions';
import { TEAM_TYPE } from '../definitions/ITeam';
import { updateSettings } from '../actions/settings';
import { compareServerVersion } from './utils';
import reduxStore from './createStore';
import { store as reduxStore } from './auxStore';
import database from './database';
import subscribeRooms from './methods/subscriptions/rooms';
import { getUserPresence, subscribeUsersPresence } from './methods/getUsersPresence';
Expand Down
2 changes: 1 addition & 1 deletion app/notifications/push/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EJSON from 'ejson';

import store from '../../lib/createStore';
import { store } from '../../lib/auxStore';
import { deepLinkingOpen } from '../../actions/deepLinking';
import { isFDroidBuild } from '../../constants/environment';
import PushNotification from './push';
Expand Down
2 changes: 1 addition & 1 deletion app/notifications/push/push.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// TODO BUMP LIB VERSION
import NotificationsIOS, { NotificationAction, NotificationCategory, Notification } from 'react-native-notifications';

import reduxStore from '../../lib/createStore';
import { store as reduxStore } from '../../lib/auxStore';
import I18n from '../../i18n';
import { INotification } from '../../definitions/INotification';

Expand Down
8 changes: 4 additions & 4 deletions app/reducers/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ export interface IShareUser {
}

export interface IShare {
user: IShareUser | {};
server: IShareServer | {};
user: IShareUser;
server: IShareServer;
settings: TShareSettings;
}

export const initialState: IShare = {
user: {},
server: {},
user: {} as IShareUser,
server: {} as IShareServer,
settings: {}
};

Expand Down
3 changes: 3 additions & 0 deletions app/share.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { defaultTheme, newThemeState, subscribeTheme, unsubscribeTheme } from '.
import UserPreferences from './lib/userPreferences';
import Navigation from './lib/ShareNavigation';
import store from './lib/createStore';
import { initStore } from './lib/auxStore';
import { supportSystemTheme } from './utils/deviceInfo';
import { defaultHeader, getActiveRouteName, navigationTheme, themedHeader } from './utils/navigation';
import RocketChat, { THEME_PREFERENCES_KEY } from './lib/rocketchat';
Expand All @@ -28,6 +29,8 @@ import { DimensionsContext } from './dimensions';
import debounce from './utils/debounce';
import { ShareInsideStackParamList, ShareOutsideStackParamList, ShareAppStackParamList } from './definitions/navigationTypes';

initStore(store);

interface IDimensions {
width: number;
height: number;
Expand Down
2 changes: 1 addition & 1 deletion app/utils/isReadOnly.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import RocketChat from '../lib/rocketchat';
import reduxStore from '../lib/createStore';
import { store as reduxStore } from '../lib/auxStore';
import { ISubscription } from '../definitions/ISubscription';

const canPostReadOnly = async ({ rid }: { rid: string }) => {
Expand Down
2 changes: 1 addition & 1 deletion app/utils/localAuthentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AsyncStorage from '@react-native-community/async-storage';
import { sha256 } from 'js-sha256';

import UserPreferences from '../lib/userPreferences';
import store from '../lib/createStore';
import { store } from '../lib/auxStore';
import database from '../lib/database';
import {
ATTEMPTS_KEY,
Expand Down