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 8, 2022. It is now read-only.

Commit807f89f

Browse files
authored
chore(ts-workflow): more js -> ts day2 (#1016)
* chore(ts-workflow): perfer Type instead of Interface* chore(ts-workflow): add @typs/react && improve defaultProps style* chore(ts-workflow): page workflow* chore(ts-workflow): make sure mst-view helper has return type* chore(ts-workflow): add some note for rootStore* chore(ts-workflow): community page -> ts, resolve warnings
1 parentecdd06b commit807f89f

File tree

22 files changed

+237
-169
lines changed

22 files changed

+237
-169
lines changed

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@
143143
"@types/jest":"^26.0.20",
144144
"@types/mocha":"^8.2.1",
145145
"@types/ramda":"^0.27.38",
146+
"@types/react":"^17.0.3",
146147
"@typescript-eslint/eslint-plugin":"^4.17.0",
147148
"@typescript-eslint/parser":"^4.17.0",
148149
"babel-eslint":"^10.0.2",

‎src/components/AlertBar/index.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import { Wrapper } from './styles'
1313
/* eslint-disable-next-line */
1414
constlog=buildLog('c:AlertBar:index')
1515

16-
typeIProps={
16+
typeTProps={
1717
children:React.ReactNode
1818
}
1919

20-
constAlertBar:React.FC<IProps>=({ children})=>{
20+
constAlertBar:React.FC<TProps>=({ children})=>{
2121
return<Wrappertestid="alertBar">{children}</Wrapper>
2222
}
2323

‎src/components/ErrorPage/index.js‎renamed to ‎src/components/ErrorPage/index.tsx‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
*/
66

77
importReactfrom'react'
8-
importTfrom'prop-types'
98
import{useRouter}from'next/router'
109
importLinkfrom'next/link'
11-
import{values}from'ramda'
1210

1311
import{METRIC}from'@/constant'
1412
import{ICON_BASE}from'@/config'
@@ -35,7 +33,19 @@ import {
3533
/* eslint-disable-next-line */
3634
constlog=buildLog('c:ErrorPage:index')
3735

38-
constErrorPage=({ testid, errorCode, metric, target})=>{
36+
exporttypeTProps={
37+
errorCode?:number// 400 | 500 | 404
38+
target?:string
39+
testid?:string
40+
metric?:string
41+
}
42+
43+
constErrorPage:React.FC<TProps>=({
44+
testid='error-page',
45+
errorCode,
46+
metric=METRIC.COMMUNITY,
47+
target='',
48+
})=>{
3949
constrouter=useRouter()
4050

4151
return(
@@ -51,7 +61,7 @@ const ErrorPage = ({ testid, errorCode, metric, target }) => {
5161
<HintWrapper>
5262
<IconsWrapper>
5363
<SpinPlanet/>
54-
<CodeSnippetserrorCode={errorCode}path={target||router.asPath}/>
64+
<CodeSnippetspath={target||router.asPath}/>
5565
</IconsWrapper>
5666
<TextWrapper>
5767
{/** TODO: */}
@@ -67,19 +77,4 @@ const ErrorPage = ({ testid, errorCode, metric, target }) => {
6777
</Wrapper>
6878
)
6979
}
70-
71-
ErrorPage.propTypes={
72-
testid:T.string,
73-
errorCode:T.oneOf([404,500]),
74-
metric:T.oneOf(values(METRIC)),
75-
target:T.string,
76-
}
77-
78-
ErrorPage.defaultProps={
79-
testid:'error-page',
80-
errorCode:404,
81-
metric:METRIC.COMMUNITY,
82-
target:'',
83-
}
84-
8580
exportdefaultReact.memo(ErrorPage)

‎src/containers/content/HelpCenterContent/Digest.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import {
1515
HelpTitle,
1616
}from'./styles/digest'
1717

18-
interfaceIProps{
18+
typeTProps={
1919
community:TCommunity
20-
metric?:string// METRIC.HELP_CENTER
20+
metric:string
2121
}
2222

23-
constDigest:React.FC<IProps>=({ metric, community})=>{
23+
constDigest:React.FC<TProps>=({ metric, community})=>{
2424
return(
2525
<Wrappermetric={metric}>
2626
<InnerWrappermetric={metric}>

‎src/containers/content/HelpCenterContent/index.tsx‎

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import React from 'react'
1111
import{METRIC}from'@/constant'
1212
import{pluggedIn,buildLog}from'@/utils'
1313

14-
import{IStore}from'./store'
14+
import{TStore}from'./store'
1515

1616
importCoverfrom'./Cover'
1717
importDetailfrom'./Detail'
@@ -25,21 +25,16 @@ import { useInit } from './logic'
2525
/* eslint-disable-next-line */
2626
constlog=buildLog('C:HelpCenterContent')
2727

28-
interfaceIProps{
29-
helpCenterContent?:IStore
30-
testid:string
31-
metric:string// METRIC.HELP_CENTER
28+
typeTProps={
29+
helpCenterContent?:TStore
30+
testid?:string
31+
metric?:string
3232
}
3333

34-
constdefaultProps:IProps={
35-
metric:METRIC.HELP_CENTER,
36-
testid:'help-center-content',
37-
}
38-
39-
constHelpCenterContentContainer:React.FC<IProps>=({
34+
constHelpCenterContentContainer:React.FC<TProps>=({
4035
helpCenterContent:store,
41-
testid,
42-
metric,
36+
testid='help-center-content',
37+
metric=METRIC.HELP_CENTER,
4338
})=>{
4439
useInit(store)
4540
const{ view, curCommunity}=store
@@ -54,16 +49,4 @@ const HelpCenterContentContainer: React.FC<IProps> = ({
5449
)
5550
}
5651

57-
HelpCenterContentContainer.defaultProps=defaultProps
58-
// HelpCenterContentContainer.propTypes = {
59-
// helpCenterContent: T.any.isRequired,
60-
// testid: T.string,
61-
// metric: T.oneOf(values(METRIC)),
62-
// }
63-
64-
// HelpCenterContentContainer.defaultProps = {
65-
// testid: 'help-center-content',
66-
// metric: METRIC.HELP_CENTER,
67-
// }
68-
69-
exportdefaultpluggedIn(HelpCenterContentContainer)
52+
exportdefaultpluggedIn(HelpCenterContentContainer)asReact.FC<TProps>

‎src/containers/content/HelpCenterContent/logic.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { useEffect } from 'react'
44
import{buildLog}from'@/utils'
55
// import S from './service'
66
import{VIEW}from'./constant'
7-
import{IStore}from'./store'
7+
import{TStore}from'./store'
88

9-
letstore:IStore|undefined
9+
letstore:TStore|undefined
1010

1111
/* eslint-disable-next-line */
1212
constlog=buildLog('L:HelpCenterContent')
@@ -22,7 +22,7 @@ export const gotoDetail = (): void => {
2222
// init & uninit handlers
2323
// ###############################
2424

25-
exportconstuseInit=(_store:IStore):void=>{
25+
exportconstuseInit=(_store:TStore):void=>{
2626
useEffect(()=>{
2727
store=_store
2828
log('useInit: ',store)

‎src/containers/content/HelpCenterContent/store.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import{typesasT,getParent,Instance}from'mobx-state-tree'
77
import{values}from'ramda'
88

9-
import{TCommunity,IRootStore}from'@/types'
9+
import{IRootStore}from'@/stores/RootStore'
10+
11+
import{TCommunity}from'@/types'
1012
import{markStates,buildLog,stripMobx}from'@/utils'
1113

1214
import{VIEW}from'./constant'
@@ -31,5 +33,5 @@ export const HelpCenterContent = T.model('HelpCenterContent', {
3133
},
3234
}))
3335

34-
exporttypeIStore=Instance<typeofHelpCenterContent>
36+
exporttypeTStore=Instance<typeofHelpCenterContent>
3537
exportdefaultHelpCenterContent

‎src/containers/layout/GlobalLayout/dynamic.js‎renamed to ‎src/containers/layout/GlobalLayout/dynamic.tsx‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
importReactfrom'react'
22
importdynamicfrom'next/dynamic'
33

4+
import{TPropsasTErrorPage}from'@/components/ErrorPage'
5+
46
exportconstDoraemon=dynamic(()=>import('@/containers/tool/Doraemon'),{
57
/* eslint-disable react/display-name */
68
loading:()=><div/>,
@@ -18,8 +20,12 @@ export const Footer = dynamic(() => import('@/containers/unit/Footer'), {
1820
loading:()=><div/>,
1921
ssr:false,
2022
})
21-
exportconstErrorPage=dynamic(()=>import('@/components/ErrorPage'),{
22-
/* eslint-disable react/display-name */
23-
loading:()=><div/>,
24-
ssr:false,
25-
})
23+
24+
exportconstErrorPage=dynamic<TErrorPage>(
25+
()=>import('@/components/ErrorPage'),
26+
{
27+
/* eslint-disable react/display-name */
28+
loading:()=><div/>,
29+
ssr:false,
30+
},
31+
)

‎src/containers/layout/GlobalLayout/index.js‎renamed to ‎src/containers/layout/GlobalLayout/index.tsx‎

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
*/
66

77
importReact,{useEffect}from'react'
8-
importTfrom'prop-types'
9-
import{values}from'ramda'
108

11-
import{ANCHOR,METRIC}from'@/constant'
9+
import{ANCHOR}from'@/constant'
1210
importAnalysisServicefrom'@/services/Analysis'
1311
import{useNetwork,useShortcut,usePlatform,useDevice}from'@/hooks'
1412
import{pluggedIn}from'@/utils'
13+
import{Nullable,TSEO}from'@/types'
1514

1615
importThemePalettefrom'@/containers/layout/ThemePalette'
1716
importHeaderfrom'@/containers/unit/Header'
@@ -20,6 +19,7 @@ import ModeLine from '@/containers/unit/ModeLine'
2019
importDrawerfrom'@/containers/tool/Drawer'
2120
importCustomScrollerfrom'@/components/CustomScroller'
2221

22+
import{TStore}from'./store'
2323
importSEOfrom'./SEO'
2424
import{Doraemon,ErrorBox,Footer,ErrorPage}from'./dynamic'
2525

@@ -33,14 +33,26 @@ import {
3333
childrenWithProps,
3434
}from'./logic'
3535

36-
constGlobalLayoutContainer=({
36+
typeTProps={
37+
globalLayout?:TStore
38+
children:React.ReactNode
39+
seoConfig:TSEO
40+
errorCode?:number// 400 | 500 | 404
41+
errorPath?:Nullable<string>
42+
noSidebar?:boolean
43+
noFooter?:boolean
44+
45+
metric:string
46+
}
47+
48+
constGlobalLayoutContainer:React.FC<TProps>=({
3749
globalLayout:store,
3850
seoConfig,
3951
errorCode,
4052
errorPath,
4153
children,
42-
noSidebar,
43-
noFooter,
54+
noSidebar=false,
55+
noFooter=false,
4456
metric,
4557
})=>{
4658
const{ online}=useNetwork()
@@ -116,24 +128,4 @@ const GlobalLayoutContainer = ({
116128
)
117129
}
118130

119-
GlobalLayoutContainer.propTypes={
120-
children:T.node,
121-
globalLayout:T.object.isRequired,
122-
seoConfig:T.object.isRequired,// TODO:
123-
noSidebar:T.bool,
124-
noFooter:T.bool,
125-
metric:T.oneOf(values(METRIC)),
126-
errorCode:T.oneOf([null,404,500]),
127-
errorPath:T.oneOfType([T.string,T.instanceOf(null)]),
128-
}
129-
130-
GlobalLayoutContainer.defaultProps={
131-
children:<div/>,
132-
noSidebar:false,
133-
noFooter:false,
134-
errorCode:null,
135-
errorPath:null,
136-
metric:METRIC.COMMUNITY,
137-
}
138-
139-
exportdefaultpluggedIn(GlobalLayoutContainer)
131+
exportdefaultpluggedIn(GlobalLayoutContainer)asReact.FC<TProps>
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
*GlobalLayoutStore store
2+
*GlobalLayout store
33
*
44
*/
55

6-
import{typesasT,getParent}from'mobx-state-tree'
6+
import{typesasT,getParent,Instance}from'mobx-state-tree'
77

88
import{markStates,buildLog}from'@/utils'
9+
import{IRootStore,TAccount}from'@/types'
910

1011
/* eslint-disable-next-line */
1112
constlog=buildLog('S:GlobalLayoutStore')
@@ -18,31 +19,33 @@ const Platform = T.model('Platform', {
1819
isEdge:T.optional(T.boolean,false),
1920
})
2021

21-
constGlobalLayoutStore=T.model('GlobalLayoutStore',{
22+
constGlobalLayout=T.model('GlobalLayoutStore',{
2223
online:T.optional(T.boolean,true),
2324
platform:T.optional(Platform,{}),
2425
isMobile:T.optional(T.boolean,false),
2526
// follow the mac convention
2627
bodyScrollDirection:T.optional(T.enumeration(['up','down']),'up'),
2728
})
2829
.views((self)=>({
29-
getroot(){
30-
returngetParent(self)
30+
getaccountInfo():TAccount{
31+
constroot=getParent(self)asIRootStore
32+
returnroot.accountInfo
3133
},
32-
getaccountInfo(){
33-
returnself.root.accountInfo
34-
},
35-
getsidebarPin(){
36-
returnself.root.sidebar.pin
34+
getsidebarPin():boolean{
35+
constroot=getParent(self)asIRootStore
36+
returnroot.sidebar.pin
3737
},
3838
}))
3939
.actions((self)=>({
40-
openDoraemon(){
41-
self.root.openDoraemon()
40+
openDoraemon():void{
41+
constroot=getParent(self)asIRootStore
42+
root.openDoraemon()
4243
},
4344
mark(sobj){
4445
markStates(sobj,self)
4546
},
4647
}))
4748

48-
exportdefaultGlobalLayoutStore
49+
exporttypeTStore=Instance<typeofGlobalLayout>
50+
51+
exportdefaultGlobalLayout

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp