From 8a62cd386e1663428ad562c681bc9d01abe4d4ab Mon Sep 17 00:00:00 2001 From: Rokt33r Date: Sat, 2 Jan 2016 04:18:08 +0900 Subject: [PATCH] add uncacheArticle, uncacheAllArticles action --- browser/main/actions.js | 26 ++++++++++++++++++-------- browser/main/reducer.js | 12 ++++++++++++ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/browser/main/actions.js b/browser/main/actions.js index 0f816416..37e02f58 100644 --- a/browser/main/actions.js +++ b/browser/main/actions.js @@ -1,12 +1,14 @@ // Action types export const USER_UPDATE = 'USER_UPDATE' -export const CLEAR_NEW_ARTICLE = 'CLEAR_NEW_ARTICLE' export const ARTICLE_UPDATE = 'ARTICLE_UPDATE' export const ARTICLE_DESTROY = 'ARTICLE_DESTROY' export const ARTICLE_SAVE = 'ARTICLE_SAVE' export const ARTICLE_SAVE_ALL = 'ARTICLE_SAVE_ALL' export const ARTICLE_CACHE = 'ARTICLE_CACHE' +export const ARTICLE_UNCACHE = 'ARTICLE_UNCACHE' +export const ARTICLE_UNCACHE_ALL = 'ARTICLE_UNCACHE_ALL' + export const FOLDER_CREATE = 'FOLDER_CREATE' export const FOLDER_UPDATE = 'FOLDER_UPDATE' export const FOLDER_DESTROY = 'FOLDER_DESTROY' @@ -31,12 +33,6 @@ export function updateUser (input) { } // DB -export function clearNewArticle () { - return { - type: CLEAR_NEW_ARTICLE - } -} - export function cacheArticle (key, article) { return { type: ARTICLE_CACHE, @@ -44,6 +40,19 @@ export function cacheArticle (key, article) { } } +export function uncacheArticle (key) { + return { + type: ARTICLE_UNCACHE, + data: { key } + } +} + +export function uncacheAllArticles () { + return { + type: ARTICLE_UNCACHE_ALL + } +} + export function saveArticle (key, article, forceSwitch) { return { type: ARTICLE_SAVE, @@ -147,10 +156,11 @@ export function toggleTutorial () { export default { updateUser, - clearNewArticle, updateArticle, destroyArticle, cacheArticle, + uncacheArticle, + uncacheAllArticles, saveArticle, saveAllArticles, diff --git a/browser/main/reducer.js b/browser/main/reducer.js index 1879d3f1..01cbf58e 100644 --- a/browser/main/reducer.js +++ b/browser/main/reducer.js @@ -16,6 +16,8 @@ import { ARTICLE_UPDATE, ARTICLE_DESTROY, ARTICLE_CACHE, + ARTICLE_UNCACHE, + ARTICLE_UNCACHE_ALL, ARTICLE_SAVE, ARTICLE_SAVE_ALL, @@ -169,6 +171,16 @@ function articles (state = initialArticles, action) { else Object.assign(state.modified[modifiedIndex], modified) return state } + case ARTICLE_UNCACHE: + { + let targetKey = action.data.key + let modifiedIndex = _.findIndex(state.modified, _article => targetKey === _article.key) + if (modifiedIndex >= 0) state.modified.splice(modifiedIndex, 1) + return state + } + case ARTICLE_UNCACHE_ALL: + state.modified = [] + return state case ARTICLE_SAVE: { let targetKey = action.data.key