@@ -20,7 +20,7 @@ const sr71$ = new SR71()
2020const debug = makeDebugger ( 'L:AccountEditor' )
2121/* eslint-enable no-unused-vars */
2222
23- let accountEditor = null
23+ let store = null
2424
2525export function goBack ( ) {
2626 dispatchEvent ( EVENT . PREVIEW , {
@@ -29,14 +29,12 @@ export function goBack() {
2929}
3030
3131export const profileChange = R . curry ( ( thread , e ) => {
32- accountEditor . updateUser ( {
32+ store . updateUser ( {
3333 [ thread ] : e . target . value ,
3434 } )
3535} )
3636
37- export function sexChange ( sex ) {
38- accountEditor . updateUser ( { sex } )
39- }
37+ export const sexChange = sex => store . updateUser ( { sex } )
4038
4139const updatableAttrs = [
4240 'nickname' ,
@@ -56,31 +54,29 @@ const hasValue = R.compose(R.not, nilOrEmpty)
5654const pickUpdatable = R . compose ( R . pickBy ( hasValue ) , R . pick ( updatableAttrs ) )
5755
5856export const updateConfirm = ( ) => {
59- if ( ! accountEditor . statusClean ) return false
57+ if ( ! store . statusClean ) return false
6058 // TODO: 只去除 null 的即可,如果为空也是合法的
61- const editing = pickUpdatable ( accountEditor . accountInfo )
62- const origin = pickUpdatable ( accountEditor . accountOrigin )
59+ const editing = pickUpdatable ( store . accountInfo )
60+ const origin = pickUpdatable ( store . accountOrigin )
6361 /* debug('editing: ', editing) */
6462 /* debug('origin: ', origin) */
6563
6664 // TODO: 唯一的限制是 昵称不能为空
6765 if ( R . equals ( editing , origin ) ) {
68- meteorState ( accountEditor , 'warn' , 3 )
66+ meteorState ( store , 'warn' , 3 )
6967 return false
7068 }
7169
72- accountEditor . markState ( {
73- updating : true ,
74- } )
70+ store . markState ( { updating : true } )
7571
7672 sr71$ . mutate ( S . updateProfile , { profile : editing } )
7773
7874 /*
7975 setTimeout(() => {
80- accountEditor .markState({
76+ store .markState({
8177 updating: false,
8278 })
83- meteorState(accountEditor , 'error', 5, '自定义错误')
79+ meteorState(store , 'error', 5, '自定义错误')
8480 }, 3000)
8581 */
8682}
@@ -90,20 +86,17 @@ export function cancleEdit() {
9086}
9187
9288export function updateDone ( ) {
93- const editing = pickUpdatable ( accountEditor . accountInfo )
94- accountEditor . updateOrign ( editing )
89+ const editing = pickUpdatable ( store . accountInfo )
90+ store . updateOrign ( editing )
9591}
9692
97- const cancleLoading = ( ) => {
98- accountEditor . markState ( {
99- updating : false ,
100- } )
101- }
93+ const cancleLoading = ( ) => store . markState ( { updating : false } )
94+
10295const DataSolver = [
10396 {
10497 match : asyncRes ( 'updateProfile' ) ,
10598 action : ( ) => {
106- meteorState ( accountEditor , 'success' , 3 )
99+ meteorState ( store , 'success' , 3 )
107100 updateDone ( )
108101 cancleLoading ( )
109102 // communitiesContent.loadCommunities(data)
@@ -116,7 +109,7 @@ const ErrSolver = [
116109 match : asyncErr ( ERR . CRAPHQL ) ,
117110 action : ( { details } ) => {
118111 const errMsg = details [ 0 ] . detail
119- meteorState ( accountEditor , 'error' , 5 , errMsg )
112+ meteorState ( store , 'error' , 5 , errMsg )
120113 cancleLoading ( )
121114 } ,
122115 } ,
@@ -137,7 +130,7 @@ const ErrSolver = [
137130]
138131
139132export function init ( selectedStore ) {
140- accountEditor = selectedStore
141- accountEditor . copyAccountInfo ( )
133+ store = selectedStore
134+ store . copyAccountInfo ( )
142135 sr71$ . data ( ) . subscribe ( $solver ( DataSolver , ErrSolver ) )
143136}
0 commit comments