-
Notifications
You must be signed in to change notification settings - Fork 1
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
Migrate Redux to Mobx #118
base: dev
Are you sure you want to change the base?
Changes from 5 commits
12bd63a
0d82ab9
b78ece7
bb59063
01f880e
fbe7282
4464f95
de8acc1
c498f9b
0242a7e
aa6425a
2e8e5be
7911573
f0f2fe6
050d65b
06e216b
c228829
de6d0bf
c8db2eb
69ecd52
20fb3c8
c585644
cf7efce
31943bc
ebfc803
3c7cb90
777494b
1492bce
6f32b2f
151e111
c9e5cee
04aa03f
d1b8221
75739a7
52ead4e
4377929
eb0acd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Observer } from 'mobx-react'; | ||
import React from 'react'; | ||
import { useStores } from '../hooks'; | ||
|
||
// Use as an example of how to use the useStores hook - will delete later | ||
export const Dummy = () => { | ||
const { console } = useStores(); | ||
|
||
return <Observer>{() => <div>{console.consoleUnread}</div>}</Observer> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { storesContext } from './stores'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
import { RootStore } from '../stores'; | ||
|
||
export const storesContext = React.createContext(RootStore); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useStores } from './useStores'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import React from 'react'; | ||
import { storesContext } from '../contexts'; | ||
|
||
export const useStores = () => React.useContext(storesContext); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { makeAutoObservable } from 'mobx'; | ||
import { RootStore } from './root'; | ||
|
||
export class ConsoleStore { | ||
rootStore: typeof RootStore; | ||
|
||
showConsole = false; | ||
consoleData: string[] = []; | ||
disableScroll = false; | ||
consoleUnread = false; | ||
|
||
constructor(rootStore: typeof RootStore) { | ||
makeAutoObservable(this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
this.rootStore = rootStore; | ||
} | ||
|
||
updateConsole = (value: string[]) => { | ||
this.consoleData = [...this.consoleData, ...value]; | ||
this.consoleUnread = !this.consoleUnread; | ||
}; | ||
|
||
clearConsole = () => { | ||
this.consoleData = []; | ||
}; | ||
|
||
toggleConsole = () => { | ||
this.showConsole = !this.showConsole; | ||
this.consoleUnread = false; | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { RootStore } from './root'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { ConsoleStore } from './console'; | ||
// Make sure store imports are in alphabetical order | ||
|
||
class RootStore_ { | ||
console: ConsoleStore; | ||
|
||
constructor() { | ||
this.console = new ConsoleStore(this); | ||
/** Initialize more stores here (try to keep it in alphabetical order) */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After defining a Store, make sure to create an instance of it in the |
||
} | ||
} | ||
|
||
export const RootStore = new RootStore_(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6302,6 +6302,23 @@ mkdirp@^1.0.4: | |
resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" | ||
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== | ||
|
||
mobx-react-lite@^3.2.0: | ||
version "3.2.0" | ||
resolved "https://registry.yarnpkg.com/mobx-react-lite/-/mobx-react-lite-3.2.0.tgz#331d7365a6b053378dfe9c087315b4e41c5df69f" | ||
integrity sha512-q5+UHIqYCOpBoFm/PElDuOhbcatvTllgRp3M1s+Hp5j0Z6XNgDbgqxawJ0ZAUEyKM8X1zs70PCuhAIzX1f4Q/g== | ||
|
||
mobx-react@^7.2.0: | ||
version "7.2.0" | ||
resolved "https://registry.yarnpkg.com/mobx-react/-/mobx-react-7.2.0.tgz#241e925e963bb83a31d269f65f9f379e37ecbaeb" | ||
integrity sha512-KHUjZ3HBmZlNnPd1M82jcdVsQRDlfym38zJhZEs33VxyVQTvL77hODCArq6+C1P1k/6erEeo2R7rpE7ZeOL7dg== | ||
dependencies: | ||
mobx-react-lite "^3.2.0" | ||
|
||
mobx@^6.3.2: | ||
version "6.3.2" | ||
resolved "https://registry.yarnpkg.com/mobx/-/mobx-6.3.2.tgz#125590961f702a572c139ab69392bea416d2e51b" | ||
integrity sha512-xGPM9dIE1qkK9Nrhevp0gzpsmELKU4MFUJRORW/jqxVFIHHWIoQrjDjL8vkwoJYY3C2CeVJqgvl38hgKTalTWg== | ||
|
||
[email protected]: | ||
version "5.0.0" | ||
resolved "https://registry.yarnpkg.com/mocha/-/mocha-5.0.0.tgz#cccac988b0bc5477119cba0e43de7af6d6ad8f4e" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a better way to declare the type of
RootStore
but we'll just leave it like this for now.