From c65e09d6f138c3f79a21badcab6fbbe7f4c70ee2 Mon Sep 17 00:00:00 2001 From: David Broder-Rodgers Date: Mon, 18 Dec 2017 15:55:04 +0000 Subject: [PATCH] Add transformState function to redux-localstorage --- types/redux-localstorage/index.d.ts | 2 ++ types/redux-localstorage/redux-localstorage-tests.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/types/redux-localstorage/index.d.ts b/types/redux-localstorage/index.d.ts index b4af824d9b..b788fcd963 100644 --- a/types/redux-localstorage/index.d.ts +++ b/types/redux-localstorage/index.d.ts @@ -26,4 +26,6 @@ export function mergePersistedState(merge?: (initialState: A1, persisten export default function persistState(storage?: StorageAdapter, key?: string, callback?: Function): Redux.GenericStoreEnhancer; +export function transformState(down: ((state: A1) => A2) | Array<(state: any) => any>, up: ((state: A2) => A1) | Array<(state: any) => any>): (storage: StorageAdapter) => A2; + export const actionTypes: ActionTypes; diff --git a/types/redux-localstorage/redux-localstorage-tests.ts b/types/redux-localstorage/redux-localstorage-tests.ts index 49bf442fcf..17f453423a 100644 --- a/types/redux-localstorage/redux-localstorage-tests.ts +++ b/types/redux-localstorage/redux-localstorage-tests.ts @@ -2,6 +2,7 @@ import { Reducer, compose, combineReducers, createStore } from "redux"; import { default as persistState, mergePersistedState, + transformState, actionTypes } from "redux-localstorage"; import * as adapterAsyncStorage from "redux-localstorage/lib/adapters/AsyncStorage"; @@ -31,3 +32,7 @@ const createStoreLocalStorage = compose( const createStoreSessionStorage = compose( persistState(storageSessionStorage, "foo") )(createStore)(reducer); + +const storage = compose( + transformState([JSON.stringify, btoa], [atob, JSON.parse]) +)(storageLocalStorage);