Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 9d44fa1

Browse files
committed
syntax sugar for storeSelector
1 parent 8d62205 commit 9d44fa1

File tree

11 files changed

+24
-55
lines changed

11 files changed

+24
-55
lines changed

containers/Body/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import R from 'ramda'
1212
// import Link from 'next/link'
1313
import { Button } from '../../components'
1414

15-
import { makeDebugger } from '../../utils/functions'
15+
import { makeDebugger, storeSelector } from '../../utils/functions'
1616

1717
import * as SuggestionIcons from '../Doraemon/styles/suggestionIcons'
1818
import * as logic from './logic'
@@ -78,10 +78,6 @@ const AppBanner = ({ route }) => {
7878
)
7979
}
8080

81-
const storeSelector = ({ store }) => ({
82-
body: store.body,
83-
})
84-
8581
class ContentContainer extends React.Component {
8682
componentWillMount() {
8783
logic.init(this.props.body)
@@ -109,4 +105,4 @@ class ContentContainer extends React.Component {
109105
}
110106
}
111107

112-
export default inject(storeSelector)(observer(ContentContainer))
108+
export default inject(storeSelector('body'))(observer(ContentContainer))

containers/Decrator/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import React from 'react'
88
import { inject, observer } from 'mobx-react'
99
import styled, { ThemeProvider } from 'styled-components'
10+
1011
// import { selection } from 'polished'
1112

13+
import { storeSelector } from '../../utils/functions'
1214
import { theme } from '../../utils/themes'
1315
import globalStyles from '../../utils/global_styles'
1416
// import observer from '../../utils/mobx_utils'
@@ -45,11 +47,6 @@ const Container = styled.div`
4547
background-color: ${theme('selection_bg')};
4648
}
4749
`
48-
49-
const storeSelector = ({ store }) => ({
50-
theme: store.theme,
51-
})
52-
5350
const ThemeObserver = ({ children, theme }) => (
5451
<ThemeProvider theme={theme.themeData}>
5552
<Container>
@@ -61,4 +58,4 @@ const ThemeObserver = ({ children, theme }) => (
6158
</ThemeProvider>
6259
)
6360

64-
export default inject(storeSelector)(observer(ThemeObserver))
61+
export default inject(storeSelector('theme'))(observer(ThemeObserver))

containers/Doraemon/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { inject, observer } from 'mobx-react'
1010
// import Link from 'next/link'
1111
// import styled from 'styled-components'
1212

13-
import { makeDebugger } from '../../utils/functions'
13+
import { makeDebugger, storeSelector } from '../../utils/functions'
1414

1515
import InputEditor from './InputEditor'
1616
import NodeIcon from './NodeIcon'
@@ -45,10 +45,6 @@ const HintIcon = ({ index, active, cur }) => {
4545
)
4646
}
4747

48-
const storeSelector = ({ store }) => ({
49-
doraemon: store.doraemon,
50-
})
51-
5248
class DoraemonContainer extends React.Component {
5349
componentWillMount() {
5450
debug('mount')
@@ -98,4 +94,4 @@ class DoraemonContainer extends React.Component {
9894
}
9995
}
10096

101-
export default inject(storeSelector)(observer(DoraemonContainer))
97+
export default inject(storeSelector('doraemon'))(observer(DoraemonContainer))

containers/Doraemon/logic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export function navToSuggestion(suggestion) {
175175
}
176176

177177
export function hidePanel() {
178-
// doraemon.hideDoraemon()
178+
doraemon.hideDoraemon()
179179
pockect$.stop()
180180
}
181181

containers/GithubSearchPanel/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { inject, observer } from 'mobx-react'
1111
// import styled from 'styled-components'
1212

1313
import A from '../../components/A'
14-
import { makeDebugger } from '../../utils/functions'
14+
import { makeDebugger, storeSelector } from '../../utils/functions'
1515
import * as logic from './logic'
1616

1717
import {
@@ -51,10 +51,6 @@ const SearchEditor = ({ value, searching }) => (
5151
</EditorBar>
5252
)
5353

54-
const storeSelector = ({ store }) => ({
55-
github: store.github,
56-
})
57-
5854
class UniversePanelContainer extends React.Component {
5955
// TODO use componentWillMount?
6056
componentWillMount() {
@@ -101,4 +97,4 @@ class UniversePanelContainer extends React.Component {
10197
}
10298
}
10399

104-
export default inject(storeSelector)(observer(UniversePanelContainer))
100+
export default inject(storeSelector('github'))(observer(UniversePanelContainer))

containers/IntroBody/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import keydown from 'react-keydown'
1111
// import Link from 'next/link'
1212
// import styled from 'styled-components'
1313

14-
import { makeDebugger } from '../../utils/functions'
14+
import { makeDebugger, storeSelector } from '../../utils/functions'
1515
import * as logic from './logic'
1616

1717
import { Body } from './styles'
@@ -45,10 +45,6 @@ const IntroPage = ({ route, doraemonVisable, curTheme, themeKeys }) => {
4545
}
4646
}
4747

48-
const storeSelector = ({ store }) => ({
49-
body: store.body,
50-
})
51-
5248
class ContentContainer extends React.Component {
5349
componentWillMount() {
5450
logic.init(this.props.body)
@@ -81,4 +77,4 @@ class ContentContainer extends React.Component {
8177
}
8278
}
8379

84-
export default inject(storeSelector)(observer(ContentContainer))
80+
export default inject(storeSelector('body'))(observer(ContentContainer))

containers/IntroSidebar/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { inject, observer } from 'mobx-react'
1414

1515
// import observer from '../../utils/mobx_utils'
1616

17+
import { makeDebugger, storeSelector } from '../../utils/functions'
1718
import { Sidebar, MenuItem } from './styles'
1819
import PinButton from './PinButton'
1920

@@ -26,7 +27,6 @@ import {
2627
CmdIcon,
2728
GraphQLIcon,
2829
} from './MenuIcon'
29-
import { makeDebugger } from '../../utils/functions'
3030
import * as logic from './logic'
3131

3232
const debug = makeDebugger('C:IntroSidebar:index')
@@ -75,10 +75,6 @@ const MenuList = ({ items, open }) => {
7575
return <MenuItem>{listItems}</MenuItem>
7676
}
7777

78-
const storeSelector = ({ store }) => ({
79-
sidebar: store.sidebar,
80-
})
81-
8278
class IntroSidebarContainer extends React.Component {
8379
componentDidMount() {
8480
debug('init')
@@ -111,4 +107,4 @@ class IntroSidebarContainer extends React.Component {
111107
}
112108
}
113109

114-
export default inject(storeSelector)(observer(IntroSidebarContainer))
110+
export default inject(storeSelector('sidebar'))(observer(IntroSidebarContainer))

containers/Preview/index.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { inject, observer } from 'mobx-react'
99

1010
// import Link from 'next/link'
1111

12-
import { makeDebugger } from '../../utils/functions'
12+
import { makeDebugger, storeSelector } from '../../utils/functions'
1313
import * as logic from './logic'
1414
import {
1515
PreviewOverlay,
@@ -32,10 +32,6 @@ const CloseBtn = ({ type }) => (
3232
</PreviewCloser>
3333
)
3434

35-
const storeSelector = ({ store }) => ({
36-
preview: store.preview,
37-
})
38-
3935
class PreviewContainer extends React.Component {
4036
componentWillMount() {
4137
debug('mount')
@@ -60,4 +56,4 @@ class PreviewContainer extends React.Component {
6056
}
6157
}
6258

63-
export default inject(storeSelector)(observer(PreviewContainer))
59+
export default inject(storeSelector('preview'))(observer(PreviewContainer))

containers/Sidebar/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import { inject, observer } from 'mobx-react'
1212
import * as SuggestionIcons from '../../containers/Doraemon/styles/suggestionIcons'
1313
// import { makeDebugger } from '../../utils/functions'
1414

15-
import { Sidebar, MenuItem, Row, SVGIconWrapper } from './styles'
15+
import { makeDebugger, storeSelector } from '../../utils/functions'
1616
import PinButton from './PinButton'
17-
import { makeDebugger } from '../../utils/functions'
17+
import { Sidebar, MenuItem, Row, SVGIconWrapper } from './styles'
1818
import * as logic from './logic'
1919

2020
const debug = makeDebugger('C:Sidebar:index')
@@ -60,10 +60,6 @@ const MenuList = ({ items, open }) => {
6060
return <MenuItem>{listItems}</MenuItem>
6161
}
6262

63-
const storeSelector = ({ store }) => ({
64-
sidebar: store.sidebar,
65-
})
66-
6763
class SidebarContainer extends React.Component {
6864
componentDidMount() {
6965
debug('init')
@@ -90,4 +86,4 @@ class SidebarContainer extends React.Component {
9086
}
9187
}
9288

93-
export default inject(storeSelector)(observer(SidebarContainer))
89+
export default inject(storeSelector('sidebar'))(observer(SidebarContainer))

utils/functions/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const isObject = value => {
1212
}
1313
/* eslint-enable */
1414

15+
export const storeSelector = R.curry((wantedStore, props) => ({
16+
[wantedStore]: R.path(['store', wantedStore], props),
17+
}))
18+
1519
export const markStates = (sobj, self) => {
1620
if (!isObject(sobj)) {
1721
throw new Error('markState get no object params')

0 commit comments

Comments
 (0)