Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commitffd71de

Browse files
committed
refactor(route): base root menu switch
1 parent0c8219c commitffd71de

File tree

18 files changed

+128
-210
lines changed

18 files changed

+128
-210
lines changed

‎containers/CommunitiesBanner/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class CommunitiesBannerContainer extends React.Component {
113113
const{ curRoute}=communitiesBanner
114114

115115
// console.log('totalCount --> ', communitiesBanner.totalCount)
116+
console.log('the fucking curRoute: ',curRoute)
116117
return(
117118
<BannerContainer>
118119
<ChildBannercurRoute={curRoute}store={stripMobx(communitiesBanner)}/>

‎containers/CommunitiesContent/logic.js‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
EVENT,
1212
TYPE,
1313
THREAD,
14+
ROUTE,
1415
scrollIntoEle,
1516
closePreviewer,
1617
dispatchEvent,
@@ -21,7 +22,12 @@ import S from './schema'
2122
importSR71from'../../utils/network/sr71'
2223

2324
constsr71$=newSR71({
24-
resv_event:[EVENT.LOGOUT,EVENT.LOGIN,EVENT.PREVIEW_CLOSE],
25+
resv_event:[
26+
EVENT.LOGOUT,
27+
EVENT.LOGIN,
28+
EVENT.PREVIEW_CLOSE,
29+
EVENT.SIDEBAR_MENU_CHANGE,
30+
],
2531
})
2632

2733
/* eslint-disable no-unused-vars */
@@ -364,6 +370,23 @@ const DataSolver = [
364370
}
365371
},
366372
},
373+
{
374+
match:asyncRes(EVENT.SIDEBAR_MENU_CHANGE),
375+
action:res=>{
376+
const{ mainPath, subPath}=res[EVENT.SIDEBAR_MENU_CHANGE].data
377+
if(mainPath!==ROUTE.COMMUNITIES)returnfalse
378+
debug('unknow event: ',subPath)
379+
380+
switch(subPath){
381+
caseROUTE.CATEGORIES:{
382+
returnloadCategories()
383+
}
384+
default:{
385+
returnloadCommunities()
386+
}
387+
}
388+
},
389+
},
367390
]
368391

369392
constErrSolver=[

‎containers/CommunitiesContent/schema.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ const pagedCategories = gql`
88
query($filter: PagedFilter!) {
99
pagedCategories(filter: $filter) {
1010
entries {
11-
${F.category}
11+
id
12+
title
13+
raw
14+
index
1215
communities {
1316
id
1417
logo

‎containers/Route/index.js‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,37 @@
77
importReactfrom'react'
88
import{inject,observer}from'mobx-react'
99
importRouter,{withRouter}from'next/router'
10-
// import Router, { withRouter } from 'next/router'
1110

1211
// import Link from 'next/link'
1312

1413
import{makeDebugger,storePlug}from'../../utils'
15-
import{init,syncRoute}from'./logic'
14+
import{init,routeChange}from'./logic'
1615

1716
/* eslint-disable no-unused-vars */
1817
constdebug=makeDebugger('C:Route')
1918
/* eslint-enable no-unused-vars */
2019

2120
classRouteContainerextendsReact.Component{
21+
/*
22+
constructor(props) {
23+
super(props)
24+
25+
const { route, router } = props
26+
init(route, router)
27+
28+
Router.onRouteChangeComplete = () => {
29+
const { route } = props
30+
routeChange(route)
31+
}
32+
}
33+
*/
2234
componentDidMount(){
2335
const{ route, router}=this.props
24-
init(route)
25-
syncRoute(router)
36+
init(route,router)
37+
2638
Router.onRouteChangeComplete=()=>{
27-
// Router.onRouteChangeStart = url => {
28-
syncRoute(router)
39+
const{ route}=this.props
40+
routeChange(route)
2941
}
3042
}
3143

‎containers/Route/logic.js‎

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,49 @@
1+
// import R from 'ramda'
2+
13
import{
24
makeDebugger,
35
getMainPath,
46
getSubPath,
7+
onClient,
8+
Global,
59
// queryStringToJSON /* isEmptyNil, getParameterByName */,
610
}from'../../utils'
711

812
/* eslint-disable no-unused-vars */
913
constdebug=makeDebugger('L:Route')
1014
/* eslint-enable no-unused-vars */
15+
letstore=null
1116

12-
letroute=null
17+
exportfunctionrouteChange(){
18+
if(onClient){
19+
constbrowserMainPath=getMainPath({asPath:Global.location.pathname})
20+
constbrowserSubPath=getSubPath({asPath:Global.location.pathname})
1321

14-
exportfunctionsyncRoute(routeObj){
15-
constmainPath=getMainPath(routeObj)
16-
constsubPath=getSubPath(routeObj)
22+
/*
23+
debug('browserMainPath -> ', browserMainPath)
24+
debug('browserSubPath -> ', browserSubPath)
1725
18-
const{ query}=routeObj
26+
debug('store.mainPath: ', store.mainPath)
27+
debug('store.subPath: ', store.subPath)
28+
*/
29+
30+
constpathChange=
31+
store.mainPath!==browserMainPath||store.subPath!==browserSubPath
1932

20-
route.markState({
21-
mainPath,
22-
subPath,
23-
query,
24-
})
33+
if(pathChange){
34+
store.markState({mainPath:browserMainPath,subPath:browserSubPath})
35+
}
36+
}
2537
}
2638

27-
exportfunctioninit(selectedStore){
28-
route=selectedStore
39+
exportfunctioninit(_store,routeObj){
40+
if(store)returnfalse
41+
store=_store
42+
43+
// sync init router info
44+
constmainPath=getMainPath(routeObj)
45+
constsubPath=getSubPath(routeObj)
46+
const{ query}=routeObj
47+
48+
store.markState({ mainPath, subPath, query})
2949
}

‎stores/RouteStore/index.js‎renamed to ‎containers/Route/store.js‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
*/
55

6-
import{typesast}from'mobx-state-tree'
6+
import{typesast,getParent}from'mobx-state-tree'
77
importRfrom'ramda'
88
importRouterfrom'next/router'
99

@@ -16,6 +16,7 @@ const debug = makeDebugger('S:RouteStore')
1616
constQuery=t.model('Query',{
1717
page:t.optional(t.string,'1'),
1818
size:t.optional(t.string,String(PAGE_SIZE.D)),
19+
tab:t.maybeNull(t.string),
1920
// sort .... [when, ...]
2021
// view ... [chart, list ...]
2122
})
@@ -27,18 +28,15 @@ const RouteStore = t
2728
query:t.optional(Query,{}),
2829
})
2930
.views(self=>({
31+
getroot(){
32+
returngetParent(self)
33+
},
3034
getcurRoute(){
3135
const{ mainPath, subPath}=self
3236
return{ mainPath, subPath}
3337
},
3438
}))
3539
.actions(self=>({
36-
// /communities/posts ..
37-
// /communities/jobs ..
38-
// .....
39-
// /javascript/posts ..
40-
// /racket/jobs ..
41-
4240
markRoute(query){
4341
if(!onClient)returnfalse
4442
const{ mainPath, subPath, page}=query

‎containers/Sidebar/CommunitiesRootMenuItem.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
2222
<ChildrenWrapperactive={activeRaw===curRaw}>
2323
<ChildrenItem
2424
active={ROUTE.COMMUNITIES===activeThread}
25-
onClick={logic.onMenuSelect.bind(this,'communities','index')}
25+
onClick={logic.onRootMenuSelect.bind(this,'communities','index')}
2626
>
2727
<ChildrenItemInner>
2828
<ChildrenTitle>社区</ChildrenTitle>
@@ -31,7 +31,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
3131
</ChildrenItem>
3232
<ChildrenItem
3333
active={ROUTE.CATEGORIES===activeThread}
34-
onClick={logic.onMenuSelect.bind(this,'communities','categories')}
34+
onClick={logic.onRootMenuSelect.bind(this,'communities','categories')}
3535
>
3636
<ChildrenItemInner>
3737
<ChildrenTitle>分类</ChildrenTitle>
@@ -40,7 +40,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
4040
</ChildrenItem>
4141
<ChildrenItem
4242
active={ROUTE.TAGS===activeThread}
43-
onClick={logic.onMenuSelect.bind(this,'communities','tags')}
43+
onClick={logic.onRootMenuSelect.bind(this,'communities','tags')}
4444
>
4545
<ChildrenItemInner>
4646
<ChildrenTitle>标签</ChildrenTitle>
@@ -49,7 +49,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
4949
</ChildrenItem>
5050
<ChildrenItem
5151
active={ROUTE.EDITORS===activeThread}
52-
onClick={logic.onMenuSelect.bind(this,'communities','editors')}
52+
onClick={logic.onRootMenuSelect.bind(this,'communities','editors')}
5353
>
5454
<ChildrenItemInner>
5555
<ChildrenTitle>编辑</ChildrenTitle>
@@ -58,7 +58,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
5858
</ChildrenItem>
5959
<ChildrenItem
6060
active={ROUTE.THREADS===activeThread}
61-
onClick={logic.onMenuSelect.bind(this,'communities','threads')}
61+
onClick={logic.onRootMenuSelect.bind(this,'communities','threads')}
6262
>
6363
<ChildrenItemInner>
6464
<ChildrenTitle>Threads</ChildrenTitle>
@@ -67,7 +67,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
6767
</ChildrenItem>
6868
<ChildrenItem
6969
active={ROUTE.POSTS===activeThread}
70-
onClick={logic.onMenuSelect.bind(this,'communities','posts')}
70+
onClick={logic.onRootMenuSelect.bind(this,'communities','posts')}
7171
>
7272
<ChildrenItemInner>
7373
<ChildrenTitle>帖子</ChildrenTitle>
@@ -76,7 +76,7 @@ const MenuChildren = ({ activeRaw, curRaw, activeThread }) => (
7676
</ChildrenItem>
7777
<ChildrenItem
7878
active={ROUTE.JOBS===activeThread}
79-
onClick={logic.onMenuSelect.bind(this,'communities','jobs')}
79+
onClick={logic.onRootMenuSelect.bind(this,'communities','jobs')}
8080
>
8181
<ChildrenItemInner>
8282
<ChildrenTitle>招聘</ChildrenTitle>

‎containers/Sidebar/index.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class SidebarContainer extends React.Component {
5858
logic.init(sidebar)
5959
}
6060

61+
componentWillUnmount(){
62+
logic.uninit()
63+
}
64+
6165
render(){
6266
const{ sidebar}=this.props
6367
const{ subscribedCommunities, activeRaw, activeThread}=sidebar

‎containers/Sidebar/logic.js‎

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
makeDebugger,
1212
EVENT,
1313
ROUTE,
14+
// TYPE,
15+
dispatchEvent,
1416
}from'../../utils'
1517
importSfrom'./schema'
1618
import{PAGE_SIZE}from'../../config'
@@ -22,6 +24,7 @@ const sr71$ = new SR71({
2224
})
2325

2426
letstore=null
27+
letsub$=null
2528

2629
/* eslint-disable no-unused-vars */
2730
constdebug=makeDebugger('L:Sidebar')
@@ -53,8 +56,16 @@ export function extendMenuBar(communityRaw) {
5356
}
5457
}
5558

56-
exportfunctiononMenuSelect(mainPath,subPath){
59+
exportfunctiononRootMenuSelect(mainPath,subPath){
60+
console.log('onRootMenuSelect mainPath: ',mainPath)
61+
console.log('onRootMenuSelect subPath: ',subPath)
62+
5763
store.markRoute({ mainPath, subPath})
64+
65+
dispatchEvent(EVENT.SIDEBAR_MENU_CHANGE,{
66+
// type: TYPE.SIDEBAR_MENU_CHANGE,
67+
data:{ mainPath, subPath},
68+
})
5869
}
5970

6071
exportfunctiononCommunityChildMenuChange(activeThread){
@@ -104,6 +115,15 @@ const ErrSolver = [
104115

105116
exportfunctioninit(selectedStore){
106117
store=selectedStore
107-
sr71$.data().subscribe($solver(DataSolver,ErrSolver))
118+
if(sub$)returnfalse
119+
sub$=sr71$.data().subscribe($solver(DataSolver,ErrSolver))
108120
// loadCommunities()
109121
}
122+
123+
exportfunctionuninit(){
124+
if(!sub$)returnfalse
125+
126+
debug('===== do uninit')
127+
sub$.unsubscribe()
128+
sub$=null
129+
}

‎stores/SidebarStore/index.js‎renamed to ‎containers/Sidebar/store.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ const SidebarStore = t
9191
},
9292

9393
/*
94-
loadSubscribedCommunities(data) {
95-
self.root.account.loadSubscribedCommunities(data)
96-
},
97-
*/
94+
loadSubscribedCommunities(data) {
95+
self.root.account.loadSubscribedCommunities(data)
96+
},
97+
*/
9898
markState(sobj){
9999
markStates(sobj,self)
100100
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp