Skip to content

Commit

Permalink
Migrate from mobx-react to mobx-react-lite / Removed mobx-utils Depen…
Browse files Browse the repository at this point in the history
…dency (#17759)

* fix: 🚑 replace mobx-react with mobx-react-lite

* refactor(trader): ♻️ refactor getPositionById method

* chore: resolve package-lock.json
  • Loading branch information
heorhi-deriv authored Dec 30, 2024
1 parent 221fcf7 commit 114a2e8
Show file tree
Hide file tree
Showing 51 changed files with 84 additions and 99 deletions.
44 changes: 4 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/account/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module.exports = function (env) {
'@deriv/hooks': '@deriv/hooks',
'@deriv/stores': '@deriv/stores',
'@deriv/utils': '@deriv/utils',
'@deriv/quill-icons': `@deriv/quill-icons`,
'@deriv/quill-icons': '@deriv/quill-icons',
'@deriv-com/utils': '@deriv-com/utils',
'@deriv-com/translations': '@deriv-com/translations',
},
Expand Down
3 changes: 2 additions & 1 deletion packages/appstore/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ module.exports = function (env) {
'react-dom': true,
classnames: true,
mobx: true,
'mobx-react-lite': true,
'react-router': true,
'react-router-dom': true,
'@deriv/shared': true,
Expand All @@ -210,7 +211,7 @@ module.exports = function (env) {
'@deriv/cashier': true,
'@deriv/cfd': true,
'@deriv/utils': true,
'@deriv-com/analytics': `@deriv-com/analytics`,
'@deriv-com/analytics': '@deriv-com/analytics',
'@deriv-com/translations': '@deriv-com/translations',
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-skeleton/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"localforage": "^1.9.0",
"lz-string": "^1.4.4",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"mobx-react-lite": "^3.4.0",
"redux": "^4.0.1",
"redux-thunk": "^2.2.0",
"shx": "^0.3.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"lodash.debounce": "^4.0.8",
"lz-string": "^1.4.4",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"mobx-react-lite": "^3.4.0",
"moment": "^2.29.2",
"pako": "^1.0.11",
"prop-types": "^15.7.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import BotBuilderTourDesktop from './bot-builder-tour-desktop';
import BotBuilderTourMobile from './bot-builder-tour-mobile';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import OnboardingTourDesktop from './onboarding-tour-desktop';
import OnboardingTourMobile from './onboarding-tour-mobile';

Expand Down
2 changes: 1 addition & 1 deletion packages/bot-web-ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module.exports = function (env) {
formik: 'formik',
react: 'react',
mobx: 'mobx',
'mobx-react': 'mobx-react',
'mobx-react-lite': 'mobx-react-lite',
'react-dom': 'react-dom',
'@deriv/utils': '@deriv/utils',
'@deriv/deriv-charts': '@deriv/deriv-charts',
Expand Down
1 change: 1 addition & 0 deletions packages/cashier/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module.exports = function (env) {
'react-router-dom': 'react-router-dom',
'react-router': 'react-router',
mobx: 'mobx',
'mobx-react-lite': 'mobx-react-lite',
'@deriv/p2p': '@deriv/p2p',
'@deriv/shared': '@deriv/shared',
'@deriv/components': '@deriv/components',
Expand Down
1 change: 1 addition & 0 deletions packages/cfd/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ module.exports = function (env) {
'react-router-dom': 'react-router-dom',
'react-router': 'react-router',
mobx: 'mobx',
'mobx-react-lite': 'mobx-react-lite',
'@deriv/account': '@deriv/account',
'@deriv/shared': '@deriv/shared',
'@deriv/components': '@deriv/components',
Expand Down
2 changes: 1 addition & 1 deletion packages/core/build/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const HOISTED_PACKAGES = {
'react-router': path.resolve(__dirname, '../../../node_modules/react-router'),
'react-router-dom': path.resolve(__dirname, '../../../node_modules/react-router-dom'),
mobx: path.resolve(__dirname, '../../../node_modules/mobx'),
'mobx-react': path.resolve(__dirname, '../../../node_modules/mobx-react'),
'mobx-react-lite': path.resolve(__dirname, '../../../node_modules/mobx-react-lite'),
'@deriv/shared': path.resolve(__dirname, '../../../node_modules/@deriv/shared'),
'@deriv/components': path.resolve(__dirname, '../../../node_modules/@deriv/components'),
'@deriv/translations': path.resolve(__dirname, '../../../node_modules/@deriv/translations'),
Expand Down
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"mobx-utils": "^6.0.5",
"mobx-react-lite": "^3.4.0",
"moment": "^2.29.2",
"null-loader": "^4.0.1",
"object.fromentries": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/App/Containers/trade-notifications.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { MobileWrapper, Money, SwipeableNotification, Text } from '@deriv/components';
import { useStore } from '@deriv/stores';
import { getCardLabels, getContractPath } from '@deriv/shared';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Components/markers/marker-line.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import PropTypes from 'prop-types';
import React from 'react';
import { Icon } from '@deriv/components';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Components/markers/marker-spot-label.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import PropTypes from 'prop-types';
import React from 'react';
import { Icon, Text } from '@deriv/components';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Components/markers/marker-spot.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import classNames from 'classnames';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import PropTypes from 'prop-types';
import React from 'react';

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/Stores/connect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useObserver } from 'mobx-react';
import { useObserver } from 'mobx-react-lite';
import React from 'react';

const isClassComponent = Component =>
Expand Down
35 changes: 25 additions & 10 deletions packages/core/src/Stores/portfolio-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import throttle from 'lodash.throttle';
import { action, computed, observable, reaction, makeObservable, override } from 'mobx';
import { computedFn } from 'mobx-utils';
import { action, computed, makeObservable, observable, override, reaction } from 'mobx';

import { Money } from '@deriv/components';
import {
ChartBarrierStore,
contractCancelled,
Expand All @@ -10,29 +11,29 @@ import {
formatPortfolioPosition,
getContractPath,
getCurrentTick,
getTotalProfit,
getDisplayStatus,
getDurationPeriod,
getDurationTime,
getDurationUnitText,
getEndTime,
getTotalProfit,
getTradeNotificationMessage,
isAccumulatorContract,
isDtraderV2DesktopEnabled,
isDtraderV2MobileEnabled,
isEmptyObject,
isEnded,
isValidToSell,
isMultiplierContract,
WS,
TRADE_TYPES,
isValidToSell,
removeBarrier,
routes,
setLimitOrderBarriers,
TRADE_TYPES,
WS,
} from '@deriv/shared';
import { Money } from '@deriv/components';
import { Analytics } from '@deriv-com/analytics';
import { localize } from '@deriv/translations';
import { Analytics } from '@deriv-com/analytics';

import BaseStore from './base-store';

export default class PortfolioStore extends BaseStore {
Expand All @@ -52,12 +53,12 @@ export default class PortfolioStore extends BaseStore {
main_barrier = null;
contract_type = '';

getPositionById = computedFn(id => this.positions.find(position => +position.id === +id));

responseQueue = [];

active_positions = [];

getPositionByIdCache = observable.map();

constructor(root_store) {
// TODO: [mobx-undecorate] verify the constructor arguments and the arguments of this automatically generated super call
super(root_store);
Expand Down Expand Up @@ -109,6 +110,17 @@ export default class PortfolioStore extends BaseStore {
this.root_store = root_store;
}

getPositionById(id) {
// Check if we already have a cached position for the given ID.
if (!this.getPositionByIdCache.has(id)) {
// Compute the position and store it in the cache.
const position = this.positions.find(position => +position.id === +id);
this.getPositionByIdCache.set(id, position);
}

return this.getPositionByIdCache.get(id);
}

async initializePortfolio() {
if (this.has_subscribed_to_poc_and_transaction) {
this.clearTable();
Expand Down Expand Up @@ -582,6 +594,9 @@ export default class PortfolioStore extends BaseStore {
}

updatePositions = () => {
// Whenever positions are updated, clear the cache to ensure consistency.
this.getPositionByIdCache.clear();

this.responseQueue.forEach(res => this.proposalOpenContractHandler(res));
this.responseQueue = [];
this.setActivePositions();
Expand Down
2 changes: 2 additions & 0 deletions packages/p2p/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ module.exports = function (env) {
'react-dom': 'react-dom',
'react-router': 'react-router',
'react-router-dom': 'react-router-dom',
mobx: 'mobx',
'mobx-react-lite': 'mobx-react-lite',
'prop-types': 'prop-types',
'@deriv-com/analytics': '@deriv-com/analytics',
'@deriv/shared': '@deriv/shared',
Expand Down
1 change: 1 addition & 0 deletions packages/reports/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = function (env) {
'react-router-dom': 'react-router-dom',
'react-router': 'react-router',
mobx: 'mobx',
'mobx-react-lite': 'mobx-react-lite',
'@deriv/shared': '@deriv/shared',
'@deriv/components': '@deriv/components',
'@deriv/translations': '@deriv/translations',
Expand Down
2 changes: 1 addition & 1 deletion packages/trader/build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module.exports = function (env) {
'react-router-dom': 'react-router-dom',
'react-router': 'react-router',
mobx: 'mobx',
'mobx-react': 'mobx-react',
'mobx-react-lite': 'mobx-react-lite',
'@deriv/shared': '@deriv/shared',
'@deriv/components': '@deriv/components',
'@deriv/translations': '@deriv/translations',
Expand Down
3 changes: 1 addition & 2 deletions packages/trader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@
"lodash.debounce": "^4.0.8",
"lodash.throttle": "^4.1.1",
"mobx": "^6.6.1",
"mobx-react": "^7.5.1",
"mobx-utils": "^6.0.5",
"mobx-react-lite": "^3.4.0",
"moment": "^2.29.2",
"null-loader": "^4.0.1",
"prop-types": "^15.7.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import classNames from 'classnames';
import clsx from 'clsx';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { Localize } from '@deriv/translations';
import { routes } from '@deriv/shared';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Button, TButtonColor } from '@deriv-com/quill-ui';
import { RemainingTime } from '@deriv/components';
import { TContractInfo, getCardLabelsV2, isMultiplierContract, isValidToCancel, isValidToSell } from '@deriv/shared';
import { useStore } from '@deriv/stores';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { TRegularSizesWithExtraLarge } from '@deriv-com/quill-ui/dist/types';
import { FormatUtils } from '@deriv-com/utils';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import clsx from 'clsx';
import { useTraderStore } from 'Stores/useTraderStores';
import { Skeleton, usePrevious } from '@deriv/components';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import clsx from 'clsx';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@deriv/stores';
import { useTraderStore } from 'Stores/useTraderStores';
import { Button, useNotifications } from '@deriv-com/quill-ui';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import clsx from 'clsx';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { Localize } from '@deriv/translations';
import { Money, Skeleton } from '@deriv/components';
import { Text } from '@deriv-com/quill-ui';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import clsx from 'clsx';
import { observer } from 'mobx-react';
import { observer } from 'mobx-react-lite';
import { ActionSheet, ToggleSwitch, Text, Heading } from '@deriv-com/quill-ui';
import { Localize } from '@deriv/translations';
import { clickAndKeyEventHandler } from '@deriv/shared';
Expand Down
Loading

0 comments on commit 114a2e8

Please sign in to comment.