Skip to content

Commit

Permalink
Merge pull request #2460 from hippware/2441
Browse files Browse the repository at this point in the history
mobx upgrade #2441
  • Loading branch information
southerneer authored Jun 7, 2018
2 parents 19ed5cf + 41c209c commit 7b80e3e
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 64 deletions.
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/NotificationBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NotificationBanner extends React.Component<any, State> {
}

componentDidMount() {
autorun('NotificationBanner', () => {
autorun(() => {
const {notificationStore} = this.props
if (notificationStore.current) {
const {isOpening, isClosing} = notificationStore.current
Expand Down
10 changes: 5 additions & 5 deletions src/components/Router.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -121,17 +121,17 @@ class TinyRobotRouter extends React.Component<Props> {
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() {
Expand Down
4 changes: 2 additions & 2 deletions src/components/map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default class Map extends React.Component<IProps> {
@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)
Expand Down Expand Up @@ -233,7 +233,7 @@ export default class Map extends React.Component<IProps> {
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) {
Expand Down
7 changes: 3 additions & 4 deletions src/store/ConnectivityStore.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -45,7 +44,7 @@ class ConnectivityStore {
this.reset()
}
},
DELAY
{delay: DELAY}
)

this.disposer2 = reaction(
Expand Down
2 changes: 1 addition & 1 deletion src/store/SearchStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions third-party/wocky-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions third-party/wocky-client/src/store/Factory.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -8,13 +9,13 @@ export type __IBot = IBot
export function createFactory(type: IType<any, any>) {
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
}
Expand Down
28 changes: 15 additions & 13 deletions third-party/wocky-client/src/store/Wocky.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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: '',
})
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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')
)
}
}
)
Expand Down
4 changes: 2 additions & 2 deletions third-party/wocky-client/test/bot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 25 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 7b80e3e

Please sign in to comment.