mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-24 05:47:44 +08:00
Add definitions for redux-localstorage and main enhancers (#12580)
* Add definitions for redux-localstorage * Add definitions for redux-localstorage-filter enhancer * Add definitions for redux-localstorage-debounce enhancer
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Redux Localstorage Filter Test
|
||||
// ================================================================================
|
||||
/// <reference path="./redux-localstorage-debounce.d.ts" />
|
||||
/// <reference path="../redux-localstorage/redux-localstorage.d.ts" />
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
|
||||
// Imports
|
||||
// --------------------------------------------------------------------------------
|
||||
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")
|
||||
23
redux-localstorage-debounce/redux-localstorage-debounce.d.ts
vendored
Normal file
23
redux-localstorage-debounce/redux-localstorage-debounce.d.ts
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
// Type definitions for redux-localstorage-debounce v0.1.0
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage-debounce
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
/// <reference path="../redux-localstorage/redux-localstorage.d.ts" />
|
||||
|
||||
declare namespace ReduxLocalStorage {
|
||||
|
||||
namespace Debounce {
|
||||
interface DebounceOptions {
|
||||
maxWait?: number
|
||||
[key: string]: any
|
||||
}
|
||||
function debounce (wait: number, options?: number | DebounceOptions): <A>(adapter: StorageAdapter<A>) => StorageAdapter<A>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare module "redux-localstorage-debounce" {
|
||||
export default ReduxLocalStorage.Debounce.debounce
|
||||
}
|
||||
24
redux-localstorage-filter/redux-localstorage-filter-tests.ts
Normal file
24
redux-localstorage-filter/redux-localstorage-filter-tests.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Redux Localstorage Filter Test
|
||||
// ================================================================================
|
||||
/// <reference path="./redux-localstorage-filter.d.ts" />
|
||||
/// <reference path="../redux-localstorage/redux-localstorage.d.ts" />
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
|
||||
// Imports
|
||||
// --------------------------------------------------------------------------------
|
||||
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")
|
||||
27
redux-localstorage-filter/redux-localstorage-filter.d.ts
vendored
Normal file
27
redux-localstorage-filter/redux-localstorage-filter.d.ts
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
// Type definitions for redux-localstorage-filter v0.1.1
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage-filter
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
/// <reference path="../redux-localstorage/redux-localstorage.d.ts" />
|
||||
|
||||
declare namespace ReduxLocalStorage {
|
||||
|
||||
namespace Filter {
|
||||
function getSubset (obj: any, paths: Array<string>): any
|
||||
function filter (paths?: string | Array<string>): <A>(adapter: StorageAdapter<A>) => StorageAdapter<A>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
declare module "redux-localstorage-filter" {
|
||||
import getSubset = ReduxLocalStorage.Filter.getSubset
|
||||
|
||||
export {
|
||||
getSubset
|
||||
}
|
||||
|
||||
export default ReduxLocalStorage.Filter.filter
|
||||
|
||||
}
|
||||
40
redux-localstorage/redux-localstorage-tests.ts
Normal file
40
redux-localstorage/redux-localstorage-tests.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// Redux Localstorage Test
|
||||
// ================================================================================
|
||||
/// <reference path="./redux-localstorage.d.ts" />
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
|
||||
// Imports
|
||||
// --------------------------------------------------------------------------------
|
||||
import { 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: Redux.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)
|
||||
67
redux-localstorage/redux-localstorage.d.ts
vendored
Normal file
67
redux-localstorage/redux-localstorage.d.ts
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
// Type definitions for redux-localstorage v1.0.0-rc4
|
||||
// Project: https://github.com/elgerlambert/redux-localstorage
|
||||
// Definitions by: Karol Janyst <https://github.com/LKay>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference path="../redux/redux.d.ts" />
|
||||
|
||||
declare namespace ReduxLocalStorage {
|
||||
|
||||
interface ActionTypes {
|
||||
INIT: string
|
||||
}
|
||||
|
||||
interface AdapterCallback {
|
||||
<A>(err?: any, result?: A): void
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
interface StorageAdapterCreator<A> {
|
||||
(storage: A): StorageAdapter<A>
|
||||
}
|
||||
|
||||
interface StorageAdapterEnhancer {}
|
||||
|
||||
function mergePersistedState (merge?: <A1, A2>(initialState: A1, persistentState: A2) => A1 & A2): <A>(next: Redux.Reducer<A>) => Redux.Reducer<A>
|
||||
|
||||
function persistState<A> (storage?: StorageAdapter<A>, key?: string, callback?: Function): Redux.GenericStoreEnhancer
|
||||
|
||||
}
|
||||
|
||||
declare module "redux-localstorage/lib/adapters/AsyncStorage" {
|
||||
const adapterCreator: ReduxLocalStorage.StorageAdapterCreator<any>
|
||||
export = adapterCreator
|
||||
}
|
||||
|
||||
declare module "redux-localstorage/lib/adapters/localStorage" {
|
||||
const adapterCreator: ReduxLocalStorage.StorageAdapterCreator<Storage>
|
||||
export = adapterCreator
|
||||
}
|
||||
|
||||
declare module "redux-localstorage/lib/adapters/sessionStorage" {
|
||||
const adapterCreator: ReduxLocalStorage.StorageAdapterCreator<Storage>
|
||||
export = adapterCreator
|
||||
}
|
||||
|
||||
declare module "redux-localstorage" {
|
||||
import mergePersistedState = ReduxLocalStorage.mergePersistedState
|
||||
|
||||
const actionTypes: ReduxLocalStorage.ActionTypes
|
||||
|
||||
export type StorageAdapterEnhancer = ReduxLocalStorage.StorageAdapterEnhancer
|
||||
|
||||
export {
|
||||
mergePersistedState,
|
||||
actionTypes
|
||||
}
|
||||
|
||||
export default ReduxLocalStorage.persistState
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user