mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-01-30 13:37:35 +00:00
Add redux-persist and basic transformers (#13389)
* Add definitions for redux-persist * Add missin generic types * Add definitions for filter transformer * Add definitions for encrypt transformer * Fix header * Add definitions for compress transformer * Delete unnecessary linter configs * Change way of importing, fix tests
This commit is contained in:
parent
59ce85c4aa
commit
de2e7e96d7
9
redux-persist-transform-compress/index.d.ts
vendored
Normal file
9
redux-persist-transform-compress/index.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
// Type definitions for redux-persist-transform-compress 4.1
|
||||
// Project: https://github.com/rt2zz/redux-persist-transform-compress
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { PersistConfig, PersistTransformer } from "redux-persist";
|
||||
|
||||
export = createCompressor;
|
||||
declare function createCompressor (config?: PersistConfig): PersistTransformer;
|
||||
5
redux-persist-transform-compress/package.json
Normal file
5
redux-persist-transform-compress/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
import { createStore, Reducer, Store } from "redux"
|
||||
import { createPersistor, Persistor, PersistTransformer } from "redux-persist"
|
||||
import createCompressor = require("redux-persist-transform-compress")
|
||||
|
||||
const reducer: Reducer<any> = (state: any, action: any) => ({})
|
||||
|
||||
const compressor: PersistTransformer = createCompressor({ whitelist : ["foo"] })
|
||||
|
||||
const store: Store<any> = createStore(reducer)
|
||||
|
||||
const persistor: Persistor = createPersistor(store, { transforms : [compressor] })
|
||||
19
redux-persist-transform-compress/tsconfig.json
Normal file
19
redux-persist-transform-compress/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"redux-persist-transform-compress-tests.ts"
|
||||
]
|
||||
}
|
||||
18
redux-persist-transform-encrypt/index.d.ts
vendored
Normal file
18
redux-persist-transform-encrypt/index.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
// Type definitions for redux-persist-transform-encrypt 0.1
|
||||
// Project: https://github.com/maxdeviant/redux-persist-transform-encrypt#readme
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { PersistTransformer } from "redux-persist";
|
||||
|
||||
export as namespace ReduxPersistEncryptor;
|
||||
|
||||
export = createEncryptor;
|
||||
|
||||
declare function createEncryptor (config: createEncryptor.EncryptorConfig): PersistTransformer;
|
||||
|
||||
declare namespace createEncryptor {
|
||||
export interface EncryptorConfig {
|
||||
secretKey: string;
|
||||
}
|
||||
}
|
||||
5
redux-persist-transform-encrypt/package.json
Normal file
5
redux-persist-transform-encrypt/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
import { createStore, Reducer, Store } from "redux"
|
||||
import { createPersistor, Persistor, PersistTransformer } from "redux-persist"
|
||||
import { EncryptorConfig } from "redux-persist-transform-encrypt"
|
||||
import * as createEncryptor from "redux-persist-transform-encrypt"
|
||||
|
||||
const reducer: Reducer<any> = (state: any, action: any) => ({})
|
||||
|
||||
const config: EncryptorConfig = { secretKey : "foo" }
|
||||
const encryptor: PersistTransformer = createEncryptor(config)
|
||||
|
||||
const store: Store<any> = createStore(reducer)
|
||||
|
||||
const persistor: Persistor = createPersistor(store, { transforms : [encryptor] })
|
||||
19
redux-persist-transform-encrypt/tsconfig.json
Normal file
19
redux-persist-transform-encrypt/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"redux-persist-transform-encrypt-tests.ts"
|
||||
]
|
||||
}
|
||||
8
redux-persist-transform-filter/index.d.ts
vendored
Normal file
8
redux-persist-transform-filter/index.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
// Type definitions for redux-persist-transform-filter 0.0
|
||||
// Project: https://github.com/edy/redux-persist-transform-filter
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { PersistTransformer } from "redux-persist";
|
||||
|
||||
export default function createFilter (reducerName: string, inboundPaths?: string[], outboundPaths?: string[]): PersistTransformer;
|
||||
5
redux-persist-transform-filter/package.json
Normal file
5
redux-persist-transform-filter/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
import { createStore, Reducer, Store } from "redux"
|
||||
import { createPersistor, Persistor, PersistTransformer } from "redux-persist"
|
||||
import createFilter from "redux-persist-transform-filter"
|
||||
|
||||
const reducer: Reducer<any> = (state: any, action: any) => ({})
|
||||
|
||||
const filter: PersistTransformer = createFilter(
|
||||
"foo",
|
||||
["foo.bar"],
|
||||
["fizz.buzz"]
|
||||
)
|
||||
|
||||
const store: Store<any> = createStore(reducer)
|
||||
|
||||
const persistor: Persistor = createPersistor(store, { transforms : [filter] })
|
||||
19
redux-persist-transform-filter/tsconfig.json
Normal file
19
redux-persist-transform-filter/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"redux-persist-transform-filter-tests.ts"
|
||||
]
|
||||
}
|
||||
2
redux-persist/constants.d.ts
vendored
Normal file
2
redux-persist/constants.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export const KEY_PREFIX: string;
|
||||
export const REHYDRATE: string;
|
||||
66
redux-persist/index.d.ts
vendored
Normal file
66
redux-persist/index.d.ts
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
// Type definitions for redux-persist 4.0
|
||||
// Project: https://github.com/rt2zz/redux-persist
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { Action, GenericStoreEnhancer, Store } from "redux";
|
||||
|
||||
export interface PersistAction<S> extends Action {
|
||||
payload?: S;
|
||||
error?: any;
|
||||
}
|
||||
|
||||
export interface PersistorRehydrateOptions {
|
||||
serial?: boolean;
|
||||
}
|
||||
|
||||
export interface Persistor {
|
||||
purge(keys?: string[]): void;
|
||||
rehydrate<A>(incoming: A, options?: PersistorRehydrateOptions): A;
|
||||
pause(): void;
|
||||
resume(): void;
|
||||
}
|
||||
|
||||
export type PersistCallback<A> = (err: any, response?: A) => void;
|
||||
|
||||
export interface PersistTransformer {
|
||||
in(state: any, key: string): any;
|
||||
out(state: any, key: string): any;
|
||||
}
|
||||
|
||||
export interface PersistStorage {
|
||||
setItem(key: string, value: any, callback?: PersistCallback<void>): Promise<void>;
|
||||
getItem<A>(key: string, callback?: PersistCallback<A>): Promise<A>;
|
||||
removeItem(key: string, callback?: PersistCallback<void>): Promise<void>;
|
||||
getAllKeys<A>(callback?: PersistCallback<A>): Promise<A>;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export type PersistStateReconciler<A, B, C> = (state: A, inboundState: B, reducedState: C, log?: boolean) => C;
|
||||
|
||||
export interface PersistAutoRehydrateConfig<A, B, C> {
|
||||
stateReconcile?: PersistStateReconciler<A, B, C>;
|
||||
}
|
||||
|
||||
export interface PersistConfig {
|
||||
whitelist?: string[];
|
||||
blacklist?: string[];
|
||||
transforms?: PersistTransformer[];
|
||||
storage?: PersistStorage;
|
||||
debounce?: number;
|
||||
keyPrefix?: string;
|
||||
serialize?: (data: any) => string;
|
||||
deserialize?: (data: string) => any;
|
||||
}
|
||||
|
||||
export function autoRehydrate<A, B ,C> (config?: PersistAutoRehydrateConfig<A, B, C>): GenericStoreEnhancer;
|
||||
|
||||
export function createPersistor<A> (store: Store<A>, config?: PersistConfig): Persistor;
|
||||
|
||||
export function createTransform (inbound: any, outbound: any, config?: PersistConfig): PersistTransformer;
|
||||
|
||||
export function getStoredState(config?: PersistConfig, callback?: PersistCallback<any>): Promise<any>;
|
||||
|
||||
export function persistStore<A> (store: Store<A>, config?: PersistConfig, callback?: PersistCallback<any>): Persistor;
|
||||
|
||||
export function purgeStoredState (config?: PersistConfig, keys?: string[]): Promise<void>;
|
||||
5
redux-persist/package.json
Normal file
5
redux-persist/package.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
53
redux-persist/redux-persist-tests.ts
Normal file
53
redux-persist/redux-persist-tests.ts
Normal file
@ -0,0 +1,53 @@
|
||||
import { createStore, Store, Reducer } from "redux"
|
||||
import {
|
||||
autoRehydrate,
|
||||
createPersistor,
|
||||
createTransform,
|
||||
getStoredState,
|
||||
persistStore,
|
||||
purgeStoredState,
|
||||
PersistConfig,
|
||||
PersistAutoRehydrateConfig,
|
||||
PersistCallback,
|
||||
Persistor,
|
||||
PersistorRehydrateOptions,
|
||||
PersistTransformer
|
||||
} from "redux-persist"
|
||||
import { KEY_PREFIX, REHYDRATE } from "redux-persist/constants"
|
||||
import { asyncLocalStorage, asyncSessionStorage } from "redux-persist/storages"
|
||||
|
||||
const reducer: Reducer<any> = (state: any, action: any) => ({})
|
||||
|
||||
const persistCallback: PersistCallback<any> = (err: any, response: any) => {}
|
||||
|
||||
const transform: PersistTransformer = createTransform({}, {}, { whitelist : ["foo"] })
|
||||
|
||||
const persistConfig: PersistConfig = {
|
||||
blacklist : ["foo"],
|
||||
whitelist : ["bar"],
|
||||
storage : asyncLocalStorage,
|
||||
transforms : [transform],
|
||||
debounce : 1000,
|
||||
keyPrefix : KEY_PREFIX
|
||||
}
|
||||
|
||||
const rehydrateOptions: PersistorRehydrateOptions = { serial : true }
|
||||
|
||||
const autoRehydrateConfig: PersistAutoRehydrateConfig<any, any, any> = {
|
||||
stateReconcile: (state: any, inboundState: any, reducedState: any, log: boolean) => ({})
|
||||
}
|
||||
|
||||
const store: Store<any> = createStore(reducer, autoRehydrate(autoRehydrateConfig))
|
||||
const persistor: Persistor = persistStore(store, persistConfig, persistCallback)
|
||||
|
||||
purgeStoredState({ whitelist : ["foo"] }, ["bar"])
|
||||
|
||||
getStoredState(persistConfig, (err: any, restoredState: any) => {
|
||||
const store: Store<any> = createStore(reducer, restoredState)
|
||||
const persistor: Persistor = createPersistor(store, persistConfig)
|
||||
const secondaryPersistor: Persistor = createPersistor(store, { storage : asyncSessionStorage })
|
||||
persistor.pause()
|
||||
persistor.resume()
|
||||
persistor.purge(["foo", "bar"])
|
||||
persistor.rehydrate(restoredState, rehydrateOptions)
|
||||
})
|
||||
4
redux-persist/storages.d.ts
vendored
Normal file
4
redux-persist/storages.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import { PersistStorage } from "redux-persist";
|
||||
|
||||
export const asyncLocalStorage: PersistStorage;
|
||||
export const asyncSessionStorage: PersistStorage;
|
||||
21
redux-persist/tsconfig.json
Normal file
21
redux-persist/tsconfig.json
Normal file
@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"constants.d.ts",
|
||||
"storages.d.ts",
|
||||
"redux-persist-tests.ts"
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user