33 *
44 */
55
6- import { types as T , getParent } from 'mobx-state-tree'
6+ import { types as T , getParent , Instance } from 'mobx-state-tree'
77import {
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'
2021import { TYPE } from '@/constant'
2122import { markStates , buildLog , stripMobx , changeset } from '@/utils'
2223import { 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 >
209225export default CommentsStore
0 commit comments