Skip to content

Commit 8a62cd3

Browse files
committed
add uncacheArticle, uncacheAllArticles action
1 parent 450327f commit 8a62cd3

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

browser/main/actions.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Action types
22
export const USER_UPDATE = 'USER_UPDATE'
33

4-
export const CLEAR_NEW_ARTICLE = 'CLEAR_NEW_ARTICLE'
54
export const ARTICLE_UPDATE = 'ARTICLE_UPDATE'
65
export const ARTICLE_DESTROY = 'ARTICLE_DESTROY'
76
export const ARTICLE_SAVE = 'ARTICLE_SAVE'
87
export const ARTICLE_SAVE_ALL = 'ARTICLE_SAVE_ALL'
98
export const ARTICLE_CACHE = 'ARTICLE_CACHE'
9+
export const ARTICLE_UNCACHE = 'ARTICLE_UNCACHE'
10+
export const ARTICLE_UNCACHE_ALL = 'ARTICLE_UNCACHE_ALL'
11+
1012
export const FOLDER_CREATE = 'FOLDER_CREATE'
1113
export const FOLDER_UPDATE = 'FOLDER_UPDATE'
1214
export const FOLDER_DESTROY = 'FOLDER_DESTROY'
@@ -31,16 +33,23 @@ export function updateUser (input) {
3133
}
3234

3335
// DB
34-
export function clearNewArticle () {
36+
export function cacheArticle (key, article) {
3537
return {
36-
type: CLEAR_NEW_ARTICLE
38+
type: ARTICLE_CACHE,
39+
data: { key, article }
3740
}
3841
}
3942

40-
export function cacheArticle (key, article) {
43+
export function uncacheArticle (key) {
4144
return {
42-
type: ARTICLE_CACHE,
43-
data: { key, article }
45+
type: ARTICLE_UNCACHE,
46+
data: { key }
47+
}
48+
}
49+
50+
export function uncacheAllArticles () {
51+
return {
52+
type: ARTICLE_UNCACHE_ALL
4453
}
4554
}
4655

@@ -147,10 +156,11 @@ export function toggleTutorial () {
147156
export default {
148157
updateUser,
149158

150-
clearNewArticle,
151159
updateArticle,
152160
destroyArticle,
153161
cacheArticle,
162+
uncacheArticle,
163+
uncacheAllArticles,
154164
saveArticle,
155165
saveAllArticles,
156166

browser/main/reducer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {
1616
ARTICLE_UPDATE,
1717
ARTICLE_DESTROY,
1818
ARTICLE_CACHE,
19+
ARTICLE_UNCACHE,
20+
ARTICLE_UNCACHE_ALL,
1921
ARTICLE_SAVE,
2022
ARTICLE_SAVE_ALL,
2123

@@ -169,6 +171,16 @@ function articles (state = initialArticles, action) {
169171
else Object.assign(state.modified[modifiedIndex], modified)
170172
return state
171173
}
174+
case ARTICLE_UNCACHE:
175+
{
176+
let targetKey = action.data.key
177+
let modifiedIndex = _.findIndex(state.modified, _article => targetKey === _article.key)
178+
if (modifiedIndex >= 0) state.modified.splice(modifiedIndex, 1)
179+
return state
180+
}
181+
case ARTICLE_UNCACHE_ALL:
182+
state.modified = []
183+
return state
172184
case ARTICLE_SAVE:
173185
{
174186
let targetKey = action.data.key

0 commit comments

Comments
 (0)