Update types for Redux-state-sync (#42979)

* update types

* update test case

* add test case

* update version

* update header

Co-authored-by: aohua <aohua@percy.sg>
This commit is contained in:
MU AOHUA 2020-03-11 03:36:25 +08:00 committed by GitHub
parent 08b013bb1c
commit 0751ca13d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 10 deletions

View File

@ -1,4 +1,4 @@
// Type definitions for redux-state-sync 3.0
// Type definitions for redux-state-sync 3.1
// Project: https://github.com/AOHUA/redux-state-sync#readme
// Definitions by: MU AOHUA <https://github.com/AOHUA>
// AntonioMendez <https://github.com/AntonioMendez>
@ -21,6 +21,7 @@ export interface Config {
blacklist?: string[];
whitelist?: string[];
broadcastChannelOption?: object | null;
prepareState?: (state: any) => any;
}
export interface MessageListenerConfig {
@ -34,7 +35,9 @@ export function isActionAllowed(config: Config): (type: string) => boolean;
export function createMessageListener(config: MessageListenerConfig): void;
export function createStateSyncMiddleware(config?: Config): Middleware;
export function withReduxStateSync(
appReducer: Reducer
appReducer: Reducer,
prepareInitialStateForStore?: (state: any) => any,
): (state: any, action: AnyAction) => Reducer;
export function initStateWithPrevTab(store: Store): Store;
export function initMessageListener(store: Store): Store;
export function isActionSynced(action: AnyAction): boolean;

View File

@ -1,5 +1,5 @@
import { createStore, applyMiddleware, Action } from "redux";
import { createStateSyncMiddleware, initStateWithPrevTab, withReduxStateSync } from "redux-state-sync";
import { createStateSyncMiddleware, initStateWithPrevTab, withReduxStateSync, initMessageListener } from "redux-state-sync";
interface TestState {
a: number;
@ -7,16 +7,18 @@ interface TestState {
c: string;
}
const middleware = createStateSyncMiddleware({
channel: 'test',
predicate: (action) => true,
blacklist: [],
whitelist: [],
broadcastChannelOption: {}
});
channel: 'test',
predicate: (action) => true,
blacklist: [],
whitelist: [],
broadcastChannelOption: {},
prepareState: (state) => state,
});
function rootReducer(state: TestState, action: Action): TestState {
return state;
}
const store = createStore(withReduxStateSync(rootReducer), ['test'], applyMiddleware(middleware));
const store = createStore(withReduxStateSync(rootReducer, (state) => state), ['test'], applyMiddleware(middleware));
initStateWithPrevTab(store);
initMessageListener(store);