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

Commit dde0e02

Browse files
authored
chore(ts-js): convert some store && fix warning (#1031)
1 parent 3bf128d commit dde0e02

File tree

9 files changed

+232
-179
lines changed

9 files changed

+232
-179
lines changed

src/containers/tool/Cashier/store.js renamed to src/containers/tool/Cashier/store.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
*
44
*/
55

6-
import { types as T, getParent } from 'mobx-state-tree'
6+
import { types as T, getParent, Instance } from 'mobx-state-tree'
77
import { merge, values } from 'ramda'
88

9+
import type { TRootStore, TAccount } from '@/spec'
10+
911
import { PAYMENT_USAGE, PAYMENT_METHOD } from '@/constant'
1012
import { markStates, buildLog } from '@/utils'
1113

@@ -41,34 +43,38 @@ const Cashier = T.model('Cashier', {
4143
),
4244
})
4345
.views((self) => ({
44-
get root() {
45-
return getParent(self)
46-
},
47-
get accountInfo() {
48-
return self.root.accountInfo
46+
get accountInfo(): TAccount {
47+
const root = getParent(self) as TRootStore
48+
return root.accountInfo
4949
},
50-
get isLogin() {
51-
return self.root.account.isLogin
50+
get isLogin(): boolean {
51+
const root = getParent(self) as TRootStore
52+
return root.account.isLogin
5253
},
5354
}))
5455
.actions((self) => ({
55-
authWarning(options) {
56-
self.root.authWarning(options)
56+
authWarning(options): void {
57+
const root = getParent(self) as TRootStore
58+
root.authWarning(options)
5759
},
58-
toastDone(options) {
59-
self.root.toast('success', merge({ position: 'topCenter' }, options))
60+
toastDone(options): void {
61+
const root = getParent(self) as TRootStore
62+
root.toast('success', merge({ position: 'topCenter' }, options))
6063
},
61-
toastError(options) {
62-
self.root.toast('error', merge({ position: 'topCenter' }, options))
64+
toastError(options): void {
65+
const root = getParent(self) as TRootStore
66+
root.toast('error', merge({ position: 'topCenter' }, options))
6367
},
64-
callCashier({ paymentUsage, amount }) {
68+
callCashier({ paymentUsage, amount }): void {
6569
self.show = true
6670
self.paymentUsage = paymentUsage
71+
// @ts-ignore
6772
self.amount = String(amount)
6873
},
69-
mark(sobj) {
74+
mark(sobj: Record<string, unknown>): void {
7075
markStates(sobj, self)
7176
},
7277
}))
7378

79+
export type TStore = Instance<typeof Cashier>
7480
export default Cashier

src/containers/tool/MailBox/store.js renamed to src/containers/tool/MailBox/store.ts

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

6-
import { types as T, getParent } from 'mobx-state-tree'
6+
import { types as T, getParent, Instance } from 'mobx-state-tree'
7+
8+
import type { TRootStore } from '@/spec'
79

810
import { markStates, buildLog, stripMobx } from '@/utils'
911
import { MailStatus, PagedMentionMessages, emptyPagiData } from '@/model'
@@ -26,11 +28,9 @@ const MailBox = T.model('MailBox', {
2628
loading: T.optional(T.boolean, false),
2729
})
2830
.views((self) => ({
29-
get root() {
30-
return getParent(self)
31-
},
32-
get isLogin() {
33-
return self.root.account.isLogin
31+
get isLogin(): boolean {
32+
const root = getParent(self) as TRootStore
33+
return root.account.isLogin
3434
},
3535
get mailStatusData() {
3636
return stripMobx(self.mailStatus)
@@ -40,9 +40,10 @@ const MailBox = T.model('MailBox', {
4040
},
4141
}))
4242
.actions((self) => ({
43-
mark(sobj) {
43+
mark(sobj: Record<string, unknown>): void {
4444
markStates(sobj, self)
4545
},
4646
}))
4747

48+
export type TStore = Instance<typeof MailBox>
4849
export default MailBox

src/containers/unit/Comments/store.js renamed to src/containers/unit/Comments/store.ts

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

6-
import { types as T, getParent } from 'mobx-state-tree'
6+
import { types as T, getParent, Instance } from 'mobx-state-tree'
77
import {
88
map,
99
findIndex,
@@ -17,6 +17,7 @@ import {
1717
merge,
1818
} from 'ramda'
1919

20+
import type { TRootStore, TCommunity, TAccount, TUser, TThread } from '@/spec'
2021
import { TYPE } from '@/constant'
2122
import { markStates, buildLog, stripMobx, changeset } from '@/utils'
2223
import { Comment, PagedComments, emptyPagiData, Mention } from '@/model'
@@ -84,22 +85,23 @@ const CommentsStore = T.model('CommentsStore', {
8485
loadingFresh: T.optional(T.boolean, false),
8586
})
8687
.views((self) => ({
87-
get root() {
88-
return getParent(self)
88+
get curRoute(): any {
89+
const root = getParent(self) as TRootStore
90+
return root.curRoute
8991
},
90-
get curRoute() {
91-
return self.root.curRoute
92-
},
93-
get isLogin() {
94-
return self.root.account.isLogin
92+
get isLogin(): boolean {
93+
const root = getParent(self) as TRootStore
94+
return root.account.isLogin
9595
},
9696
get referUsersData() {
9797
const referUsers = stripMobx(self.referUsers)
9898
const extractMentions = stripMobx(self.extractMentions)
99+
// @ts-ignore
99100
return filter((user) => contains(user.name, extractMentions), referUsers)
100101
},
101-
get participators() {
102-
const { commentsParticipators } = self.root.viewing.viewingData
102+
get participators(): TUser[] {
103+
const root = getParent(self) as TRootStore
104+
const { commentsParticipators } = root.viewing.viewingData
103105
/*
104106
const commentsParticipators = [
105107
{
@@ -115,6 +117,7 @@ const CommentsStore = T.model('CommentsStore', {
115117
},
116118
]
117119
*/
120+
118121
return map(mentionMapper, commentsParticipators)
119122
},
120123
get mentionListData() {
@@ -123,49 +126,59 @@ const CommentsStore = T.model('CommentsStore', {
123126
get pagedCommentsData() {
124127
return stripMobx(self.pagedComments)
125128
},
126-
get accountInfo() {
127-
return self.root.account.accountInfo
129+
get accountInfo(): TAccount {
130+
const root = getParent(self) as TRootStore
131+
return root.account.accountInfo
128132
},
129-
get curCommunity() {
130-
return stripMobx(self.root.viewing.community)
133+
get curCommunity(): TCommunity {
134+
const root = getParent(self) as TRootStore
135+
return stripMobx(root.viewing.community)
131136
},
132-
get communityRaw() {
137+
get communityRaw(): string {
138+
const root = getParent(self) as TRootStore
133139
// const viewingCommunity = stripMobx(self.root.viewing.community)
134140
// if (viewingCommunity.raw) return viewingCommunity.raw
135141

136-
return self.root.viewing.viewingData.origialCommunity.raw
142+
return root.viewing.viewingData.origialCommunity.raw
137143
},
138-
get activeThread() {
139-
const { activeThread, viewingThread } = self.root.viewing
144+
get activeThread(): TThread {
145+
const root = getParent(self) as TRootStore
146+
const { activeThread, viewingThread } = root.viewing
140147
return toUpper(viewingThread || activeThread)
141148
},
142-
get viewingData() {
143-
return self.root.viewingData
149+
get viewingData(): any {
150+
const root = getParent(self) as TRootStore
151+
return root.viewingData
144152
},
145153
get editCommentData() {
146154
return stripMobx(self.editComment)
147155
},
148156
}))
149157
.actions((self) => ({
150-
authWarning(options) {
151-
self.root.authWarning(options)
158+
authWarning(options): void {
159+
const root = getParent(self) as TRootStore
160+
root.authWarning(options)
152161
},
153-
changesetErr(options) {
154-
self.root.changesetErr(options)
162+
changesetErr(options): void {
163+
const root = getParent(self) as TRootStore
164+
root.changesetErr(options)
155165
},
156166

157-
validator(type) {
167+
validator(type): boolean {
168+
const { changesetErr } = self as TStore
158169
switch (type) {
159170
case 'create': {
160171
const result = changeset({ editContent: self.editContent })
161-
.exist({ editContent: '评论内容' }, self.changesetErr)
172+
// @ts-ignore
173+
.exist({ editContent: '评论内容' }, changesetErr)
162174
.done()
163175

164176
return result.passed
165177
}
166178
case 'reply': {
167179
const result = changeset({ replyContent: self.replyContent })
168-
.exist({ replyContent: '回复内容' }, self.changesetErr)
180+
// @ts-ignore
181+
.exist({ replyContent: '回复内容' }, changesetErr)
169182
.done()
170183

171184
return result.passed
@@ -175,7 +188,7 @@ const CommentsStore = T.model('CommentsStore', {
175188
}
176189
}
177190
},
178-
addReferUser(user) {
191+
addReferUser(user: TUser): void {
179192
const index = findIndex((u) => u.id === String(user.id), self.referUsers)
180193
if (index === -1) {
181194
self.referUsers.push({
@@ -185,25 +198,28 @@ const CommentsStore = T.model('CommentsStore', {
185198
})
186199
}
187200
},
188-
updateMentionList(mentionArray) {
201+
updateMentionList(mentionArray): void {
189202
const curMentionList = clone(self.mentionList)
190203
const uniqList = concat(curMentionList, mentionArray)
191204
const mentionList = map(mentionMapper, uniqList)
192205

193206
// log('mentionList: ', mentionList)
194207
// log('uniq: ', R.uniq(R.concat(mentionList, self.participators)))
195208

209+
// @ts-ignore
196210
self.mentionList = uniq(concat(mentionList, self.participators))
197211
},
198-
updateOneComment(id, comment = {}) {
212+
updateOneComment(id, comment = {}): void {
199213
const { entries } = self.pagedCommentsData
200214

201215
const index = findIndex(propEq('id', id), entries)
216+
// @ts-ignore
202217
self.pagedComments.entries[index] = merge(entries[index], comment)
203218
},
204-
mark(sobj) {
219+
mark(sobj: Record<string, unknown>): void {
205220
markStates(sobj, self)
206221
},
207222
}))
208223

224+
export type TStore = Instance<typeof CommentsStore>
209225
export default CommentsStore

src/containers/unit/Sidebar/store.js

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)