Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/architecture/convention.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ we can easily import files like:

```js
import { ISSUE_WEB } from '@/config'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import ArticleEditFooter from '@/components/ArticleEditFooter'
...
Expand All @@ -68,7 +68,7 @@ Import Waypoint from 'react-waypoint'
Import R from 'ramda'

// 2. import utils
Import { connectStore, buildLog, ROUTE, THREAD } from '@/utils'
Import { pluggedIn, buildLog, ROUTE, THREAD } from '@/utils'

// 3. import global containers
Import TagsBar from '@/containers/unit/TagsBar'
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture/convention.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Doramon 为网站提供类似于 [alfred](https://www.alfredapp.com/) 的功能,

```js
import { ISSUE_WEB } from '@/config'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import ArticleEditFooter from '@/components/ArticleEditFooter'
...
Expand All @@ -67,7 +67,7 @@ import { inject, observer } from 'mobx-react'
import Waypoint from 'react-waypoint'

// 2. import utils
import { connectStore, buildLog, ROUTE, THREAD } from '@/utils'
import { pluggedIn, buildLog, ROUTE, THREAD } from '@/utils'

// 3. import global containers
import TagsBar from '@/containers/unit/TagsBar'
Expand Down
6 changes: 3 additions & 3 deletions docs/architecture/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ import Editor from './Editor'

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

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'
import { useInit, changeView, onPublish, cancelPublish } from './logic'

const PostEditorContainer = ({ postEditor: store, attachment }) =>{
Expand All @@ -181,13 +181,13 @@ const PostEditorContainer = ({ postEditor: store, attachment }) =>{
)
}

export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

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

```js
export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

#### store.js
Expand Down
6 changes: 3 additions & 3 deletions docs/architecture/intro.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ import Editor from './Editor'

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

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'
import { useInit, changeView, onPublish, cancelPublish } from './logic'

const PostEditorContainer = ({ postEditor: store, attachment }) =>{
Expand All @@ -178,13 +178,13 @@ const PostEditorContainer = ({ postEditor: store, attachment }) =>{
)
}

export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

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

```js
export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

#### store.js
Expand Down
4 changes: 2 additions & 2 deletions docs/js/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ The root state tree is a combination of the child-state-tree (store.js) scattere

#### child state tree

The substate tree exists only in the container component, named store.js, and is connected to the root state tree via [connectStore](https://github.com/coderplanets/coderplanets_web/blob/dev/utils/mobx_helper.js#L37) Take the PostEditor container as an example:
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:

```js
export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

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.
Expand Down
4 changes: 2 additions & 2 deletions docs/js/state-management.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ root 状态树由分散在各个容器组件内的子状态树(store.js) 以及

#### 子状态树

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

```js
export default connectStore(PostEditorContainer)
export default pluggedIn(PostEditorContainer)
```

相同目录下的 containers/PostEditor/store.js 只包含 PostEditor 容器所需的状态,且状态只能通过该 store 暴露出的 action 方法,由同目录下 logic.js 中的方法调用改变, 视图层无法直接改变状态。
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Route/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'
import { useRouter } from 'next/router'

import { connectStore } from '@/utils'
import { pluggedIn } from '@/utils'
import { useInit } from './logic'

const RouteContainer = ({ route }) => {
Expand All @@ -17,4 +17,4 @@ const RouteContainer = ({ route }) => {
return <div />
}

export default connectStore(RouteContainer)
export default pluggedIn(RouteContainer)
4 changes: 2 additions & 2 deletions src/containers/content/CommunityContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react'

import { ROUTE, C11N } from '@/constant'
import { useDevice } from '@/hooks'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import PostsThread from '@/containers//thread/PostsThread'
import VideosThread from '@/containers/thread/VideosThread'
Expand Down Expand Up @@ -72,4 +72,4 @@ const CommunityContentContainer = ({ communityContent: store }) => {
)
}

export default connectStore(CommunityContentContainer)
export default pluggedIn(CommunityContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/CoolGuideContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import FilterBar from './FilterBar'
import Content from './Content'
Expand Down Expand Up @@ -38,4 +38,4 @@ const CoolGuideContentContainer = ({ coolGuideContent: store, metric }) => {
)
}

export default connectStore(CoolGuideContentContainer)
export default pluggedIn(CoolGuideContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/DiscoveryContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'
import { isEmpty } from 'ramda'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import Pagi from '@/components/Pagi'

Expand Down Expand Up @@ -77,4 +77,4 @@ const DiscoveryContentContainer = ({ discoveryContent: store, metric }) => {
)
}

export default connectStore(DiscoveryContentContainer)
export default pluggedIn(DiscoveryContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/FriendsContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import { Br } from '@/components/Common'
import { FriendsGallery } from '@/components/GalleryHub'
Expand Down Expand Up @@ -117,4 +117,4 @@ const FriendsContentContainer = ({ friendsContent: store, metric }) => {
)
}

export default connectStore(FriendsContentContainer)
export default pluggedIn(FriendsContentContainer)
10 changes: 2 additions & 8 deletions src/containers/content/HaveADrinkContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import React from 'react'
import dynamic from 'next/dynamic'

import {
connectStore,
buildLog,
scrollToTop,
lockPage,
unlockPage,
} from '@/utils'
import { pluggedIn, buildLog, scrollToTop, lockPage, unlockPage } from '@/utils'
import { useShortcut } from '@/hooks'

import Header from './Header'
Expand Down Expand Up @@ -68,4 +62,4 @@ const HaveADrinkContentContainer = ({ haveADrinkContent: store }) => {
)
}

export default connectStore(HaveADrinkContentContainer)
export default pluggedIn(HaveADrinkContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/JobContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'

import { THREAD } from '@/constant'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import ArticleBodyHeader from '@/containers/unit/ArticleBodyHeader'
import Comments from '@/containers/unit/Comments'
Expand Down Expand Up @@ -84,4 +84,4 @@ const JobContentContainer = ({ jobContent: store }) => {
)
}

export default connectStore(JobContentContainer)
export default pluggedIn(JobContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/MeetupsContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react'

import { ASSETS_ENDPOINT } from '@/config'
import { GALLERY } from '@/constant'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import Pagi from '@/components/Pagi'
import { PagiOptionSwitcher } from '@/components/Switcher'
Expand Down Expand Up @@ -72,4 +72,4 @@ const MeetupsContentContainer = ({ meetupsContent: store }) => {
)
}

export default connectStore(MeetupsContentContainer)
export default pluggedIn(MeetupsContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/MembershipContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React from 'react'
import T from 'prop-types'

// import { ICON_CMD, EMAIL_BUSINESS, SENIOR_AMOUNT_THRESHOLD } from '@/config'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import { OrButton, Button } from '@/components/Buttons'
import Checker from '@/components/Checker'
Expand Down Expand Up @@ -154,4 +154,4 @@ MembershipContentContainer.defaultProps = {
testId: 'membership-content',
}

export default connectStore(MembershipContentContainer)
export default pluggedIn(MembershipContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/PostContent/DesktopView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { useRef } from 'react'
import { Waypoint } from 'react-waypoint'

import { connectStore, buildLog, isElementInViewport } from '@/utils'
import { pluggedIn, buildLog, isElementInViewport } from '@/utils'

import Comments from '@/containers/unit/Comments'
// import ArticleAuthorCard from '@/containers/unit/ArticleAuthorCard'
Expand Down Expand Up @@ -70,4 +70,4 @@ const PostContentContainer = ({ postContent: store, metric }) => {
)
}

export default connectStore(PostContentContainer)
export default pluggedIn(PostContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/PostContent/MobileView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'
import { Waypoint } from 'react-waypoint'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import Comments from '@/containers/unit/Comments'
// import ArticleAuthorCard from '@/containers/unit/ArticleAuthorCard'
Expand Down Expand Up @@ -53,4 +53,4 @@ const PostContentContainer = ({ postContent: store }) => {
)
}

export default connectStore(PostContentContainer)
export default pluggedIn(PostContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/RecipesContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'
import { RECIPE } from '@/constant'

import Snippets from './Snippets'
Expand Down Expand Up @@ -47,4 +47,4 @@ const RecipesContentContainer = ({ recipesContent: store, metric }) => {
)
}

export default connectStore(RecipesContentContainer)
export default pluggedIn(RecipesContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/RepoContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import Comments from '@/containers/unit/Comments'
import ArticleAuthorCard from '@/containers/unit/ArticleAuthorCard'
Expand Down Expand Up @@ -71,4 +71,4 @@ const RepoContentContainer = ({ repoContent: store }) => {
)
}

export default connectStore(RepoContentContainer)
export default pluggedIn(RepoContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/SponsorContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import { Br } from '@/components/Common'
import { SponsorGallery } from '@/components/GalleryHub'
Expand Down Expand Up @@ -138,4 +138,4 @@ const SponsorContentContainer = ({ sponsorContent: store, metric }) => {
)
}

export default connectStore(SponsorContentContainer)
export default pluggedIn(SponsorContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/SubscribeContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import React from 'react'
import T from 'prop-types'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import Content from './Content'
import Actions from './Actions'
Expand Down Expand Up @@ -46,4 +46,4 @@ SubscribeContentContainer.defaultProps = {
testId: 'subscribe-content',
}

export default connectStore(SubscribeContentContainer)
export default pluggedIn(SubscribeContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/TrendingContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React from 'react'

import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import { OrButton } from '@/components/Buttons'
import NewsBoard from './NewsBoard'
Expand Down Expand Up @@ -48,4 +48,4 @@ const TrendingContentContainer = ({ trendingContent: store, metric }) => {
)
}

export default connectStore(TrendingContentContainer)
export default pluggedIn(TrendingContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/UserContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'

import { USER_THREAD } from '@/constant'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import UserProfile from '@/containers/user/UserProfile'
import UserPublished from '@/containers/user/UserPublished'
Expand Down Expand Up @@ -135,4 +135,4 @@ const UserContentContainer = ({ userContent: store, metric }) => {
)
}

export default connectStore(UserContentContainer)
export default pluggedIn(UserContentContainer)
4 changes: 2 additions & 2 deletions src/containers/content/VideoContent/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React from 'react'

import { THREAD } from '@/constant'
import { connectStore, buildLog } from '@/utils'
import { pluggedIn, buildLog } from '@/utils'

import ArticleBodyHeader from '@/containers/unit/ArticleBodyHeader'
import Comments from '@/containers/unit/Comments'
Expand Down Expand Up @@ -88,4 +88,4 @@ const VideoContentContainer = ({ videoContent: store }) => {
)
}

export default connectStore(VideoContentContainer)
export default pluggedIn(VideoContentContainer)
Loading