From 41c209cfc1fa656ca93f32c44f3ef07a3210d797 Mon Sep 17 00:00:00 2001 From: aksonov Date: Thu, 7 Jun 2018 16:22:34 +0200 Subject: [PATCH] mobx upgrade #2441 --- package.json | 12 ++--- src/components/NotificationBanner.tsx | 2 +- src/components/Router.tsx | 10 ++-- src/components/map/Map.tsx | 4 +- src/store/ConnectivityStore.ts | 7 ++- src/store/SearchStore.ts | 2 +- third-party/wocky-client/package.json | 6 +-- third-party/wocky-client/src/store/Factory.ts | 5 +- third-party/wocky-client/src/store/Wocky.ts | 28 ++++++----- third-party/wocky-client/test/bot.test.ts | 4 +- yarn.lock | 49 ++++++++++--------- 11 files changed, 65 insertions(+), 64 deletions(-) diff --git a/package.json b/package.json index 514bd7b76..89274ed8b 100644 --- a/package.json +++ b/package.json @@ -98,11 +98,11 @@ "graphql-tag": "^2.8.0", "libphonenumber-js": "^0.4.29", "lodash": "^4.17.4", - "mobx": "3.3.1", - "mobx-react": "4.3.5", - "mobx-state-tree": "1.3.1", + "mobx": "^4.1.1", + "mobx-react": "^5.0.0", + "mobx-state-tree": "^2.0.5", "moment": "^2.18.1", - "mst-middlewares": "^2.0.4", + "mst-middlewares": "^2.0.5", "phoneformat.js": "github:hippware/phoneformat.js", "prop-types": "^15.6.0", "react": "16.3.1", @@ -129,7 +129,7 @@ "react-native-parsed-text": "^0.0.20", "react-native-permissions": "^1.1.1", "react-native-push-notification": "^3.0.1", - "react-native-router-flux": "4.0.0-beta.31", + "react-native-router-flux": "4.0.0-beta.32", "react-native-swipeable": "^0.6.0", "react-native-swiper": "1.5.13", "react-native-tab-view": "^0.0.73", @@ -181,8 +181,6 @@ "form-data": "^1.0.0-rc4", "husky": "^0.14.3", "jest": "^23.0.1", - "mobx": "3.3.1", - "mobx-state-tree": "1.3.1", "mocha": "^2.3.4", "mocha-steps": "^0.0.1", "nock": "^3.3.0", diff --git a/src/components/NotificationBanner.tsx b/src/components/NotificationBanner.tsx index 2f47589de..7dc0cb4ee 100644 --- a/src/components/NotificationBanner.tsx +++ b/src/components/NotificationBanner.tsx @@ -45,7 +45,7 @@ class NotificationBanner extends React.Component { } componentDidMount() { - autorun('NotificationBanner', () => { + autorun(() => { const {notificationStore} = this.props if (notificationStore.current) { const {isOpening, isClosing} = notificationStore.current diff --git a/src/components/Router.tsx b/src/components/Router.tsx index f96573311..e75fc62ff 100644 --- a/src/components/Router.tsx +++ b/src/components/Router.tsx @@ -1,6 +1,6 @@ import React from 'react' import {TouchableOpacity, Text, Keyboard} from 'react-native' -import {when, autorun, autorunAsync} from 'mobx' +import {when, autorun} from 'mobx' import {observer, inject} from 'mobx-react/native' import {colors} from '../constants' @@ -121,17 +121,17 @@ class TinyRobotRouter extends React.Component { componentDidMount() { const {wocky, locationStore, store} = this.props - autorunAsync(() => { + autorun(() => { if (wocky!.connected && !locationStore!.enabled) { if (Actions.locationWarning) Actions.locationWarning() } - }, 1000) + }, {delay: 1000}) - autorunAsync(() => { + autorun(() => { if (Actions.currentScene === '_fullMap' && !locationStore!.alwaysOn && !store.locationPrimed) { if (Actions.locationPrimer) Actions.locationPrimer() } - }, 1000) + }, {delay: 1000} ) } render() { diff --git a/src/components/map/Map.tsx b/src/components/map/Map.tsx index cbdd37f0b..60fe20ceb 100644 --- a/src/components/map/Map.tsx +++ b/src/components/map/Map.tsx @@ -75,7 +75,7 @@ export default class Map extends React.Component { @computed get botMarkerList(): any[] { const {wocky, bot} = this.props - const list = (wocky.geoBots && wocky.geoBots.values().filter(b => isAlive(b))) || [] + const list = (wocky.geoBots && Array.from(wocky.geoBots.values()).filter(b => isAlive(b))) || [] if (bot && list.indexOf(bot) === -1) { list.push(bot) @@ -233,7 +233,7 @@ export default class Map extends React.Component { return } - const list = this.props.wocky.geoBots.values() + const list = Array.from(this.props.wocky.geoBots.values()) const annotation = list.find(b => nativeEvent.id === b.id) if (!annotation) { diff --git a/src/store/ConnectivityStore.ts b/src/store/ConnectivityStore.ts index edd25ee4a..d9a4648ba 100644 --- a/src/store/ConnectivityStore.ts +++ b/src/store/ConnectivityStore.ts @@ -1,4 +1,4 @@ -import {autorunAsync, reaction, observable, action} from 'mobx' +import {autorun, reaction, observable, action} from 'mobx' import {IWocky} from 'wocky-client' export const DELAY = 1000 @@ -33,8 +33,7 @@ class ConnectivityStore { this._handleConnectionInfoChange(reach) }) - this.disposer = autorunAsync( - 'Connectivity: tryReconnect', + this.disposer = autorun( () => { const {netConnected, isActive} = this const {username, password, connected, connecting} = this.wocky! @@ -45,7 +44,7 @@ class ConnectivityStore { this.reset() } }, - DELAY + {delay: DELAY} ) this.disposer2 = reaction( diff --git a/src/store/SearchStore.ts b/src/store/SearchStore.ts index b2b98d5a4..fe8259d32 100644 --- a/src/store/SearchStore.ts +++ b/src/store/SearchStore.ts @@ -109,7 +109,7 @@ const SearchStore = types // set initial list to all friends when(() => wocky.friends.length > 0, () => self.localResult.replace(wocky.friends)) - handler2 = autorun('SearchStore', () => { + handler2 = autorun(() => { const {local} = self if (wocky.connected) { self.localResult.replace( diff --git a/third-party/wocky-client/package.json b/third-party/wocky-client/package.json index 931b0b9c9..7b78a6965 100644 --- a/third-party/wocky-client/package.json +++ b/third-party/wocky-client/package.json @@ -19,8 +19,8 @@ "chai": "4.1.2", "denodeify": "^1.2.1", "form-data": "^2.3.1", - "mobx": "3.3.1", - "mobx-state-tree": "1.3.1", + "mobx": "^4.1.1", + "mobx-state-tree": "^2.0.5", "mocha": "2.3.4", "prettier": "^1.10.2", "promise": "^8.0.1", @@ -43,7 +43,7 @@ "graphql": "^0.13.2", "graphql-tag": "^2.8.0", "moment": "^2.20.1", - "mst-middlewares": "^1.3.1", + "mst-middlewares": "^2.0.5", "node-fetch": "^2.1.2", "strophejs": "github:hippware/strophejs", "tslib": "^1.8.1", diff --git a/third-party/wocky-client/src/store/Factory.ts b/third-party/wocky-client/src/store/Factory.ts index d9e16f04c..c94d780b0 100644 --- a/third-party/wocky-client/src/store/Factory.ts +++ b/third-party/wocky-client/src/store/Factory.ts @@ -1,4 +1,5 @@ import {types, getEnv, getParent, getType, IType} from 'mobx-state-tree' +import {ObservableMap} from 'mobx' import {Profile} from '../model/Profile' import {File} from '../model/File' import {Bot, IBot} from '../model/Bot' @@ -8,13 +9,13 @@ export type __IBot = IBot export function createFactory(type: IType) { return types .model({ - storage: types.optional(types.map(type), {}), + storage: types.optional(types.map(type), {} as ObservableMap), }) .named(`Factory${type.name}`) .views(self => ({ get snapshot() { const storage: any = {} - self.storage.keys().forEach((key: string) => { + Array.from(self.storage.keys()).forEach((key: string) => { if (self.storage.get(key)!) { storage[key] = self.storage.get(key)!.snapshot } diff --git a/third-party/wocky-client/src/store/Wocky.ts b/third-party/wocky-client/src/store/Wocky.ts index 59f1dbd43..40894564c 100644 --- a/third-party/wocky-client/src/store/Wocky.ts +++ b/third-party/wocky-client/src/store/Wocky.ts @@ -11,7 +11,7 @@ import { IModelType, IExtendedObservableMap, } from 'mobx-state-tree' -import {reaction, IObservableArray} from 'mobx' +import {reaction, IObservableArray, ObservableMap} from 'mobx' import {OwnProfile} from '../model/OwnProfile' import {Profile, IProfile} from '../model/Profile' import {IFileService, upload} from '../transport/FileService' @@ -73,12 +73,12 @@ export const Wocky = types password: types.maybe(types.string), host: types.string, sessionCount: 0, - roster: types.optional(types.map(types.reference(Profile)), {}), + roster: types.optional(types.map(types.reference(Profile)), {} as ObservableMap), profile: types.maybe(OwnProfile), updates: types.optional(types.array(EventEntity), []), events: types.optional(EventList, {}), geofenceBots: types.optional(BotPaginableList, {}), - geoBots: types.optional(types.map(types.reference(Bot)), {}), + geoBots: types.optional(types.map(types.reference(Bot)), {} as ObservableMap), chats: types.optional(Chats, Chats.create()), version: '', }) @@ -130,9 +130,11 @@ export const Wocky = types return self.transport.connecting }, get sortedRoster(): IProfile[] { - return [...self.roster.values()].filter(x => x.handle).sort((a, b) => { - return a.handle!.toLocaleLowerCase().localeCompare(b.handle!.toLocaleLowerCase()) - }) + return (Array.from(self.roster.values()) as IProfile[]) + .filter(x => x.handle) + .sort((a, b) => { + return a.handle!.toLocaleLowerCase().localeCompare(b.handle!.toLocaleLowerCase()) + }) }, get updatesToAdd(): IEventEntity[] { return self.updates.filter((e: IEventEntity) => { @@ -238,7 +240,7 @@ export const Wocky = types })) .actions(self => ({ addRosterItem: (profile: any) => { - self.roster.put(self.profiles.get(profile.id, profile)) + self.roster.set(profile.id, self.profiles.get(profile.id, profile)) }, getProfile: flow(function*(id: string, data: {[key: string]: any} = {}) { const profile = self.profiles.get(id, processMap(data)) @@ -597,7 +599,7 @@ export const Wocky = types }, _onGeoBot: (bot: any) => { if (!self.geoBots.has(bot.id)) { - self.geoBots.put(self.getBot(bot)) + self.geoBots.set(bot.id, self.getBot(bot)) } }, enablePush: flow(function*(token: string) { @@ -657,13 +659,13 @@ export const Wocky = types .actions(self => { function clearCache() { self.geofenceBots.refresh() - self.profiles.clear() self.roster.clear() self.chats.clear() - self.bots.clear() self.geoBots.clear() self.events.refresh() self.updates.clear() + self.profiles.clear() + self.bots.clear() } return { clearCache, @@ -696,9 +698,9 @@ export const Wocky = types } self._subscribeToHomestream(self.version) } else { - self.profiles.storage - .values() - .forEach((profile: any) => profile.setStatus('unavailable')) + Array.from(self.profiles.storage.values()).forEach((profile: any) => + profile.setStatus('unavailable') + ) } } ) diff --git a/third-party/wocky-client/test/bot.test.ts b/third-party/wocky-client/test/bot.test.ts index beccc689d..bf0d378ea 100644 --- a/third-party/wocky-client/test/bot.test.ts +++ b/third-party/wocky-client/test/bot.test.ts @@ -203,14 +203,14 @@ describe('BotStore', () => { it('geosearch', async done => { try { - expect(user1.geoBots.keys().length).to.be.equal(0) + expect(Array.from(user1.geoBots.keys()).length).to.be.equal(0) await user1.geosearch({ latitude: 1.2, longitude: 2.2, latitudeDelta: 0.5, longitudeDelta: 0.5, }) - await waitFor(() => user1.geoBots.keys().length >= 2) + await waitFor(() => Array.from(user1.geoBots.keys()).length >= 2) done() } catch (e) { done(e) diff --git a/yarn.lock b/yarn.lock index d64212dd0..42f11de40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4132,6 +4132,10 @@ hoist-non-react-statics@^2.2.0, hoist-non-react-statics@^2.3.1: version "2.3.1" resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.3.1.tgz#343db84c6018c650778898240135a1420ee22ce0" +hoist-non-react-statics@^2.5.0: + version "2.5.0" + resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-2.5.0.tgz#d2ca2dfc19c5a91c5a6615ce8e564ef0347e2a40" + home-or-tmp@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" @@ -6037,25 +6041,20 @@ mkdirp@0.5, mkdirp@0.5.1, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1: dependencies: minimist "0.0.8" -mobx-react@4.3.5: - version "4.3.5" - resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-4.3.5.tgz#76853f2f2ef4a6f960c374bcd9f01e875929c04c" - dependencies: - hoist-non-react-statics "^2.3.1" - -mobx-react@^4.3.4: - version "4.3.4" - resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-4.3.4.tgz#58cda105b8018f9bf87bd6de333ac5eb0d5c9dfe" +mobx-react@^5.0.0: + version "5.2.0" + resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-5.2.0.tgz#d1fc36d6231a84d0ca54ebeaaa692872859d3629" dependencies: - hoist-non-react-statics "^2.3.1" + hoist-non-react-statics "^2.5.0" + react-lifecycles-compat "^3.0.2" -mobx-state-tree@1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/mobx-state-tree/-/mobx-state-tree-1.3.1.tgz#9e1ba9b8b6ea183f1a4a2ae1f67bfa8f2bcae4fe" +mobx-state-tree@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/mobx-state-tree/-/mobx-state-tree-2.0.5.tgz#99131b2a729c6eaf9de16a12d52bf19e0ee5ba1f" -mobx@3.3.1, mobx@^3.3.1: - version "3.3.1" - resolved "https://registry.yarnpkg.com/mobx/-/mobx-3.3.1.tgz#c38fc1a287a0dda3f5d4b85efe1137fedd9dcdf0" +mobx@^4.1.1: + version "4.3.1" + resolved "https://registry.yarnpkg.com/mobx/-/mobx-4.3.1.tgz#334e5aab4916b1d43f0faf3605a64b1b4b3ccb8d" mocha-steps@^0.0.1: version "0.0.1" @@ -6122,9 +6121,9 @@ ms@2.0.0, ms@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" -mst-middlewares@^2.0.4: - version "2.0.4" - resolved "https://registry.yarnpkg.com/mst-middlewares/-/mst-middlewares-2.0.4.tgz#16680bff8b759e2583161df6a37707a938744886" +mst-middlewares@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/mst-middlewares/-/mst-middlewares-2.0.5.tgz#65a003821a206a5d5c8a7b26ae280ae068e582b2" multipipe@^0.1.2: version "0.1.2" @@ -7002,6 +7001,10 @@ react-lifecycles-compat@^1.0.2: version "1.1.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-1.1.4.tgz#fc005c72849b7ed364de20a0f64ff58ebdc2009a" +react-lifecycles-compat@^3.0.2: + version "3.0.4" + resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" + react-native-actionsheet@^2.2.2: version "2.2.2" resolved "https://registry.yarnpkg.com/react-native-actionsheet/-/react-native-actionsheet-2.2.2.tgz#469075a7d1c8e5b5d0829294bf9a2c4d2eb7e34e" @@ -7180,13 +7183,11 @@ react-native-push-notification@^3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/react-native-push-notification/-/react-native-push-notification-3.0.1.tgz#0e23db302d03bb4a3f28dc072dcaf2a9a1178ed8" -react-native-router-flux@4.0.0-beta.31: - version "4.0.0-beta.31" - resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.31.tgz#edea28cbac705fbb324ae8f5eb136dc0bef1e1e8" +react-native-router-flux@4.0.0-beta.32: + version "4.0.0-beta.32" + resolved "https://registry.yarnpkg.com/react-native-router-flux/-/react-native-router-flux-4.0.0-beta.32.tgz#68fad98d42d667944c5e584649606d8fdf3b20d2" dependencies: lodash.isequal "^4.5.0" - mobx "^3.3.1" - mobx-react "^4.3.4" opencollective "^1.0.3" path-to-regexp "^2.1.0" prop-types "^15.6.0"