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

Commit 6286cf8

Browse files
authored
refactor(dev): use explicit store bond (#1267)
* refactor(container): use explicit bond to rm babel display name plugin * chore: fmt * chore: fmt
1 parent 983e5a5 commit 6286cf8

File tree

87 files changed

+2379
-2057
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2379
-2057
lines changed

.babelrc

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"presets": ["next/babel"],
33
"plugins": [
4-
"add-react-displayname",
54
[
65
"babel-plugin-styled-components",
76
{

docs/architecture/convention.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ we can easily import files like:
5050

5151
```js
5252
import { ISSUE_WEB } from '@/config'
53-
import { pluggedIn, buildLog } from '@/utils'
53+
import { bond, buildLog } from '@/utils'
5454

5555
import ArticleEditFooter from '@/widgets/ArticleEditFooter'
5656
...
@@ -68,7 +68,7 @@ Import Waypoint from 'react-waypoint'
6868
Import R from 'ramda'
6969

7070
// 2. import utils
71-
Import { pluggedIn, buildLog, ROUTE, THREAD } from '@/utils'
71+
Import { bond, buildLog, ROUTE, THREAD } from '@/utils'
7272

7373
// 3. import global containers
7474
Import TagsBar from '@/containers/unit/TagsBar'

docs/architecture/convention.zh-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Doramon 为网站提供类似于 [alfred](https://www.alfredapp.com/) 的功能,
5050

5151
```js
5252
import { ISSUE_WEB } from '@/config'
53-
import { pluggedIn, buildLog } from '@/utils'
53+
import { bond, buildLog } from '@/utils'
5454

5555
import ArticleEditFooter from '@/widgets/ArticleEditFooter'
5656
...
@@ -67,7 +67,7 @@ import { inject, observer } from 'mobx-react'
6767
import Waypoint from 'react-waypoint'
6868

6969
// 2. import utils
70-
import { pluggedIn, buildLog, ROUTE, THREAD } from '@/utils'
70+
import { bond, buildLog, ROUTE, THREAD } from '@/utils'
7171

7272
// 3. import global containers
7373
import TagsBar from '@/containers/unit/TagsBar'

docs/architecture/intro.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ import Editor from './Editor'
154154

155155
import { Wrapper, ViewerWrapper } from './styles'
156156

157-
import { pluggedIn, buildLog } from '@/utils'
157+
import { bond, buildLog } from '@/utils'
158158
import { useInit, changeView, onPublish, cancelPublish } from './logic'
159159

160160
const PostEditorContainer = ({ postEditor: store, attachment }) =>{
@@ -181,13 +181,13 @@ const PostEditorContainer = ({ postEditor: store, attachment }) =>{
181181
)
182182
}
183183

184-
export default pluggedIn(PostEditorContainer)
184+
export default bond(PostEditorContainer)
185185
```
186186

187187
Based on my own experience and the actual situation of the project's evolution over the past year, I think the local state is bad. So all the states are handed to the external state management tool [Mobx-State-Tree](https://github.com/mobxjs/mobx-state-tree), and then the container is linked to the entire project state tree by the following function. Corresponding substate trees are linked together
188188

189189
```js
190-
export default pluggedIn(PostEditorContainer)
190+
export default bond(PostEditorContainer)
191191
```
192192

193193
#### store.js

docs/architecture/intro.zh-CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ import Editor from './Editor'
151151

152152
import { Wrapper, ViewerWrapper } from './styles'
153153

154-
import { pluggedIn, buildLog } from '@/utils'
154+
import { bond, buildLog } from '@/utils'
155155
import { useInit, changeView, onPublish, cancelPublish } from './logic'
156156

157157
const PostEditorContainer = ({ postEditor: store, attachment }) =>{
@@ -178,13 +178,13 @@ const PostEditorContainer = ({ postEditor: store, attachment }) =>{
178178
)
179179
}
180180

181-
export default pluggedIn(PostEditorContainer)
181+
export default bond(PostEditorContainer)
182182
```
183183

184184
根据我自己的一些经验和项目一年来演进的实际情况,我认为局部状态是糟糕的。所以所有的状态都交于外部的状态管理工具 [Mobx-State-Tree](https://github.com/mobxjs/mobx-state-tree), 然后通过下面函数将该容器与整个项目状态树中相对应的子状态树链接起来:
185185

186186
```js
187-
export default pluggedIn(PostEditorContainer)
187+
export default bond(PostEditorContainer)
188188
```
189189

190190
#### store.js

docs/js/state-management.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ The root state tree is a combination of the child-state-tree (store.js) scattere
88

99
#### child state tree
1010

11-
The substate tree exists only in the container component, named store.js, and is connected to the root state tree via [pluggedIn](https://github.com/coderplanets/coderplanets_web/blob/dev/utils/mobx_helper.js#L37) Take the PostEditor container as an example:
11+
The substate tree exists only in the container component, named store.js, and is connected to the root state tree via [bond](https://github.com/coderplanets/coderplanets_web/blob/dev/utils/mobx_helper.js#L37) Take the PostEditor container as an example:
1212

1313
```js
14-
export default pluggedIn(PostEditorContainer)
14+
export default bond(PostEditorContainer)
1515
```
1616

1717
Containers/PostEditor/store.js in the same directory only contains the state required by the PostEditor container, and the state can only be changed by the method method exposed in the store, which is changed by the method call in logic.js in the same directory. The view layer cannot be directly Change the status.

docs/js/state-management.zh-CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ root 状态树由分散在各个容器组件内的子状态树(store.js) 以及
88

99
#### 子状态树
1010

11-
子状态树只存在于容器组件, 统一命名为 store.js, 通过 [pluggedIn](https://github.com/coderplanets/coderplanets_web/blob/dev/utils/mobx_helper.js#L37) 连接到根状态树, 以 PostEditor 容器为例:
11+
子状态树只存在于容器组件, 统一命名为 store.js, 通过 [bond](https://github.com/coderplanets/coderplanets_web/blob/dev/utils/mobx_helper.js#L37) 连接到根状态树, 以 PostEditor 容器为例:
1212

1313
```js
14-
export default pluggedIn(PostEditorContainer)
14+
export default bond(PostEditorContainer)
1515
```
1616

1717
相同目录下的 containers/PostEditor/store.js 只包含 PostEditor 容器所需的状态,且状态只能通过该 store 暴露出的 action 方法,由同目录下 logic.js 中的方法调用改变, 视图层无法直接改变状态。

next.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const withBundleAnalyzer = require('@next/bundle-analyzer')({
1313

1414
// if move pwa config to witPlugins, it will not work
1515
const nextConfig = withPWA({
16-
// swcMinify: true,
16+
swcMinify: false,
1717
productionBrowserSourceMaps: false,
1818
pwa: {
1919
dest: 'public',

0 commit comments

Comments
 (0)