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

Commit 776563b

Browse files
committed
rename store in container logic
1 parent 210a3b5 commit 776563b

File tree

23 files changed

+271
-423
lines changed

23 files changed

+271
-423
lines changed

containers/AccountEditor/logic.js

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const sr71$ = new SR71()
2020
const debug = makeDebugger('L:AccountEditor')
2121
/* eslint-enable no-unused-vars */
2222

23-
let accountEditor = null
23+
let store = null
2424

2525
export function goBack() {
2626
dispatchEvent(EVENT.PREVIEW, {
@@ -29,14 +29,12 @@ export function goBack() {
2929
}
3030

3131
export 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

4139
const updatableAttrs = [
4240
'nickname',
@@ -56,31 +54,29 @@ const hasValue = R.compose(R.not, nilOrEmpty)
5654
const pickUpdatable = R.compose(R.pickBy(hasValue), R.pick(updatableAttrs))
5755

5856
export 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

9288
export 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+
10295
const 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

139132
export function init(selectedStore) {
140-
accountEditor = selectedStore
141-
accountEditor.copyAccountInfo()
133+
store = selectedStore
134+
store.copyAccountInfo()
142135
sr71$.data().subscribe($solver(DataSolver, ErrSolver))
143136
}

containers/AccountViewer/logic.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const sr71$ = new SR71({
1919
resv_event: [EVENT.LOGIN],
2020
})
2121

22-
let accountViewer = null
22+
let store = null
2323

2424
export function loadUser() {}
2525

@@ -30,11 +30,11 @@ export function loadAccount() {
3030
}
3131

3232
export function changeTheme(name) {
33-
accountViewer.changeTheme(name)
33+
store.changeTheme(name)
3434
}
3535

3636
export function logout() {
37-
accountViewer.logout()
37+
store.logout()
3838
dispatchEvent(EVENT.LOGOUT)
3939
}
4040

@@ -50,7 +50,7 @@ const DataSolver = [
5050
match: asyncRes('account'),
5151
action: res => {
5252
const data = res.account
53-
accountViewer.updateAccount(data)
53+
store.updateAccount(data)
5454
},
5555
},
5656
{
@@ -81,6 +81,6 @@ const ErrSolver = [
8181
]
8282

8383
export function init(selectedStore) {
84-
accountViewer = selectedStore
84+
store = selectedStore
8585
sr71$.data().subscribe($solver(DataSolver, ErrSolver))
8686
}

containers/ArticleViwer/logic.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const sr71$ = new SR71({
1212
const debug = makeDebugger('L:ArticleViwer')
1313
/* eslint-enable no-unused-vars */
1414

15-
let articleViwer = null
15+
let store = null
1616
let sub$ = null
1717

1818
export function onReaction(type, action, isUndo, data) {
@@ -27,9 +27,7 @@ export function onReaction(type, action, isUndo, data) {
2727
}
2828

2929
function loading(maybe = true) {
30-
articleViwer.markState({
31-
postLoading: maybe,
32-
})
30+
store.markState({ postLoading: maybe })
3331
}
3432

3533
function queryPost(data) {
@@ -56,7 +54,7 @@ const dataResolver = [
5654
const info = res[EVENT.PREVIEW_POST]
5755
/* debug('EVENT.PREVIEW_POST: ', res[EVENT.PREVIEW_POST]) */
5856
if (info.type === TYPE.POST) {
59-
articleViwer.load(TYPE.POST, res[EVENT.PREVIEW_POST].data)
57+
store.load(TYPE.POST, res[EVENT.PREVIEW_POST].data)
6058
loading()
6159
queryPost(info.data)
6260
}
@@ -86,14 +84,14 @@ const dataResolver = [
8684
action: () => {
8785
// TODO: test
8886
sr71$.stop()
89-
articleViwer.load(TYPE.POST, {})
87+
store.load(TYPE.POST, {})
9088
loading(false)
9189
},
9290
},
9391
{
9492
match: asyncRes(R.toLower(TYPE.POST)), // GraphQL return
9593
action: res => {
96-
articleViwer.load(TYPE.POST, res[R.toLower(TYPE.POST)])
94+
store.load(TYPE.POST, res[R.toLower(TYPE.POST)])
9795
loading(false)
9896
},
9997
},
@@ -113,8 +111,8 @@ const handleData = res => {
113111
}
114112

115113
export function init(selectedStore) {
116-
articleViwer = selectedStore
117-
debug(articleViwer)
114+
store = selectedStore
115+
debug(store)
118116
if (sub$) sub$.unsubscribe()
119117

120118
sub$ = sr71$.data().subscribe(handleData)

containers/Banner/logic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let sub$ = null
1010
const debug = makeDebugger('L:Banner')
1111
/* eslint-enable no-unused-vars */
1212

13-
let banner = null
13+
let store = null
1414

1515
export function someMethod() {}
1616

@@ -22,8 +22,8 @@ const DataSolver = []
2222
const ErrSolver = []
2323

2424
export function init(selectedStore) {
25-
banner = selectedStore
26-
debug(banner)
25+
store = selectedStore
26+
debug(store)
2727
if (sub$) sub$.unsubscribe()
2828
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
2929
}

containers/CategoryEditor/logic.js

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ let sub$ = null
1818
const debug = makeDebugger('L:CategoryEditor')
1919
/* eslint-enable no-unused-vars */
2020

21-
let categoryEditor = null
21+
let store = null
2222

2323
export const profileChange = R.curry((thread, e) =>
24-
categoryEditor.updateCategory({
24+
store.updateCategory({
2525
[thread]: e.target.value,
2626
})
2727
)
2828

2929
export const mutateConfirm = () => {
3030
const requiredArgs = ['title', 'raw']
31-
const args = { ...categoryEditor.categoryData }
31+
const args = { ...store.categoryData }
3232

33-
categoryEditor.markState({ mutating: true })
33+
store.markState({ mutating: true })
3434
const fargs = castArgs(args, requiredArgs)
3535

36-
if (categoryEditor.isEdit) {
36+
if (store.isEdit) {
3737
return sr71$.mutate(
3838
S.updateCategory,
3939
castArgs(args, ['id', ...requiredArgs])
@@ -44,43 +44,34 @@ export const mutateConfirm = () => {
4444
}
4545

4646
export function cancleMutate() {
47-
categoryEditor.markState({
47+
store.markState({
4848
category: {},
4949
isEdit: false,
5050
})
5151
closePreviewer()
5252
}
5353

54-
const initEditData = editData => {
55-
categoryEditor.markState({
56-
category: editData,
57-
isEdit: true,
58-
})
59-
}
54+
const initEditData = editData =>
55+
store.markState({ category: editData, isEdit: true })
6056

6157
// ###############################
6258
// Data & Error handlers
6359
// ###############################
6460
const DataSolver = [
6561
{
6662
match: asyncRes('createCategory'),
67-
action: () => {
68-
closePreviewer(TYPE.GATEGORIES_REFRESH)
69-
},
63+
action: () => closePreviewer(TYPE.GATEGORIES_REFRESH),
7064
},
7165
{
7266
match: asyncRes('updateCategory'),
73-
action: () => {
74-
closePreviewer(TYPE.GATEGORIES_REFRESH)
75-
},
67+
action: () => closePreviewer(TYPE.GATEGORIES_REFRESH),
7668
},
7769
]
7870

7971
const ErrSolver = []
8072

8173
export function init(selectedStore, editData) {
82-
categoryEditor = selectedStore
83-
debug(categoryEditor)
74+
store = selectedStore
8475
if (sub$) sub$.unsubscribe()
8576
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
8677

containers/CategorySetter/logic.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let sub$ = null
1919
const debug = makeDebugger('L:CategorySetter')
2020
/* eslint-enable no-unused-vars */
2121

22-
let categorySetter = null
22+
let store = null
2323

2424
const commonFilter = page => {
2525
const size = PAGE_SIZE.COMMON
@@ -46,7 +46,7 @@ const DataSolver = [
4646
{
4747
match: asyncRes('pagedCategories'),
4848
action: ({ pagedCategories }) =>
49-
categorySetter.markState({
49+
store.markState({
5050
pagedCategories,
5151
}),
5252
},
@@ -59,7 +59,7 @@ const DataSolver = [
5959
const ErrSolver = []
6060

6161
export function init(selectedStore) {
62-
categorySetter = selectedStore
62+
store = selectedStore
6363
if (sub$) sub$.unsubscribe()
6464
sub$ = sr71$.data().subscribe($solver(DataSolver, ErrSolver))
6565

0 commit comments

Comments
 (0)