redux-persist-transform-encrypt 2.0 definitions (#25231)

This commit is contained in:
Gaurav Lahoti
2018-04-30 09:12:49 -07:00
committed by Andy
parent feb092e579
commit 31a5880939
3 changed files with 21 additions and 7 deletions
+6 -2
View File
@@ -1,3 +1,7 @@
import createAsyncEncryptor from ".";
import { Transform } from "redux-persist";
export default createAsyncEncryptor;
export interface AsyncEncryptorConfig {
secretKey: string;
}
export default function createAsyncEncryptor<State, Raw>(config: AsyncEncryptorConfig): Transform<State, Raw>;
+3 -1
View File
@@ -1,12 +1,14 @@
// Type definitions for redux-persist-transform-encrypt 1.0
// Type definitions for redux-persist-transform-encrypt 2.0
// Project: https://github.com/maxdeviant/redux-persist-transform-encrypt
// Definitions by: Karol Janyst <https://github.com/LKay>
// Gaurav Lahoti <https://github.com/dante-101>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
import { Transform } from "redux-persist";
export interface EncryptorConfig {
secretKey: string;
onError?: (err: Error) => void;
}
export default function createEncryptor<State, Raw>(config: EncryptorConfig): Transform<State, Raw>;
@@ -1,14 +1,22 @@
import { createStore, Reducer, Store } from "redux";
import { createPersistor, Transform } from "redux-persist";
import createEncryptor, { EncryptorConfig } from "redux-persist-transform-encrypt";
import createAsyncEncryptor from "redux-persist-transform-encrypt/async";
import createAsyncEncryptor, { AsyncEncryptorConfig } from "redux-persist-transform-encrypt/async";
const reducer: Reducer<any> = (state: any, action: any) => ({ state, action });
const config: EncryptorConfig = { secretKey : "foo" };
const config: EncryptorConfig = {
secretKey: "foo",
onError: (err: Error) => { err.message; }
};
const encryptor: Transform<any, any> = createEncryptor(config);
const asyncEncryptor: Transform<any, any> = createAsyncEncryptor(config);
const configNoError: EncryptorConfig = { secretKey: "foo" };
const encryptorNoError: Transform<any, any> = createEncryptor(configNoError);
const asyncConfig: AsyncEncryptorConfig = { secretKey: "foo" };
const asyncEncryptor: Transform<any, any> = createAsyncEncryptor(asyncConfig);
const store: Store<any> = createStore(reducer);
createPersistor(store, { transforms : [encryptor, asyncEncryptor] });
createPersistor(store, { transforms : [encryptor, encryptorNoError, asyncEncryptor] });