mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Add definitions for redux-localstorage and main enhancers (#13115)
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
||||
// Type definitions for redux-localstorage-debounce 0.1
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage-debounce
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { StorageAdapter } from "redux-localstorage";
|
||||
|
||||
interface DebounceOptions {
|
||||
maxWait?: number;
|
||||
[key: string]: any;
|
||||
}
|
||||
export default function debounce(wait: number, options?: number | DebounceOptions): <A>(adapter: StorageAdapter<A>) => StorageAdapter<A>;
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { compose } from "redux"
|
||||
import {
|
||||
default as persistState
|
||||
} from "redux-localstorage"
|
||||
import * as adapter from "redux-localstorage/lib/adapters/localStorage"
|
||||
import { default as debounce } from "redux-localstorage-debounce"
|
||||
|
||||
const storageWait = compose(
|
||||
debounce(100)
|
||||
)(adapter(window.localStorage))
|
||||
const enhancerWait = persistState(storageWait, "test")
|
||||
|
||||
const storageMax = compose(
|
||||
debounce(100, 200)
|
||||
)(adapter(window.localStorage))
|
||||
const enhancerMax = persistState(storageMax, "test")
|
||||
|
||||
const storageOpts = compose(
|
||||
debounce(100, { maxWait : 200, foo : "bar" })
|
||||
)(adapter(window.localStorage))
|
||||
const enhancerOpts = persistState(storageOpts, "test")
|
||||
@@ -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-localstorage-debounce-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
// Type definitions for redux-localstorage-filter 0.1
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage-filter
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import { StorageAdapter } from "redux-localstorage";
|
||||
|
||||
export function getSubset (obj: any, paths: string[]): any;
|
||||
export default function filter (paths?: string | string[]): <A>(adapter: StorageAdapter<A>) => StorageAdapter<A>;
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { compose } from "redux"
|
||||
import {
|
||||
default as persistState
|
||||
} from "redux-localstorage"
|
||||
import * as adapter from "redux-localstorage/lib/adapters/localStorage"
|
||||
import { default as filter } from "redux-localstorage-filter"
|
||||
|
||||
const storageSingle = compose(
|
||||
filter("foo")
|
||||
)(adapter(window.localStorage))
|
||||
const enhancerSingle = persistState(storageSingle, "test")
|
||||
|
||||
const storageMulti = compose(
|
||||
filter(["foo", "bar"])
|
||||
)(adapter(window.localStorage))
|
||||
const enhancerMulti = persistState(storageMulti, "test")
|
||||
@@ -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-localstorage-filter-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "../tslint.json" }
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
// Type definitions for redux-localstorage 1.0
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
import * as Redux from "redux";
|
||||
|
||||
export interface ActionTypes {
|
||||
INIT: string;
|
||||
}
|
||||
|
||||
export type AdapterCallback = <A>(err?: any, result?: A) => void;
|
||||
|
||||
export interface StorageAdapter<A> {
|
||||
0: A;
|
||||
put(key: string, value: any, callback: AdapterCallback): void;
|
||||
get(key: string, callback: AdapterCallback): void;
|
||||
del(key: string, callback: AdapterCallback): void;
|
||||
}
|
||||
|
||||
export type StorageAdapterCreator<A> = (storage: A) => StorageAdapter<A>;
|
||||
|
||||
export interface StorageAdapterEnhancer {}
|
||||
|
||||
export function mergePersistedState (merge?: <A1, A2>(initialState: A1, persistentState: A2) => A1 & A2): <A>(next: Redux.Reducer<A>) => Redux.Reducer<A>;
|
||||
|
||||
export default function persistState<A> (storage?: StorageAdapter<A>, key?: string, callback?: Function): Redux.GenericStoreEnhancer;
|
||||
|
||||
export const actionTypes: ActionTypes;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { StorageAdapterCreator } from "redux-localstorage";
|
||||
declare const adapterCreator: StorageAdapterCreator<any>;
|
||||
export = adapterCreator;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { StorageAdapterCreator } from "redux-localstorage";
|
||||
declare const adapterCreator: StorageAdapterCreator<Storage>;
|
||||
export = adapterCreator;
|
||||
@@ -0,0 +1,3 @@
|
||||
import { StorageAdapterCreator } from "redux-localstorage";
|
||||
declare const adapterCreator: StorageAdapterCreator<Storage>;
|
||||
export = adapterCreator;
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"redux": "^3.6.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Imports
|
||||
// --------------------------------------------------------------------------------
|
||||
import { Reducer, compose, combineReducers, createStore } from "redux"
|
||||
import {
|
||||
default as persistState,
|
||||
mergePersistedState,
|
||||
actionTypes
|
||||
} from "redux-localstorage"
|
||||
import * as adapterAsyncStorage from "redux-localstorage/lib/adapters/AsyncStorage"
|
||||
import * as adapterLocalStorage from "redux-localstorage/lib/adapters/localStorage"
|
||||
import * as adapterSessionStorage from "redux-localstorage/lib/adapters/sessionStorage"
|
||||
|
||||
const AsyncStorage: any = {}
|
||||
|
||||
const rootReducer: Reducer<any> = (state: any, action: any) => state
|
||||
|
||||
const reducer = compose(
|
||||
mergePersistedState()
|
||||
)(rootReducer)
|
||||
|
||||
const storageAsyncStorage = adapterAsyncStorage(AsyncStorage)
|
||||
const storageLocalStorage = adapterLocalStorage(window.localStorage)
|
||||
const storageSessionStorage = adapterSessionStorage(window.sessionStorage)
|
||||
|
||||
const createStoreAsyncStorage = compose(
|
||||
persistState(storageAsyncStorage, "foo")
|
||||
)(createStore)(reducer)
|
||||
|
||||
const createStoreLocalStorage = compose(
|
||||
persistState(storageLocalStorage, "foo")
|
||||
)(createStore)(reducer)
|
||||
|
||||
const createStoreSessionStorage = compose(
|
||||
persistState(storageSessionStorage, "foo")
|
||||
)(createStore)(reducer)
|
||||
@@ -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-localstorage-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
"rules": {
|
||||
"forbidden-types": false,
|
||||
"no-empty-interface": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user