Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manifest V3 #297

Merged
merged 18 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 38 additions & 32 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
import * as redux from 'redux';
import * as redux from "redux";

export type DiffStrategy = (oldObj: any, newObj: any) => any;
export type PatchStrategy = (oldObj: any, patch: any) => any;

export class Store<S = any, A extends redux.Action = redux.AnyAction> {
/**
* Creates a new Proxy store
* @param options An object of form {portName, state, extensionId}, where `portName` is a required string and defines the name of the port for state transition changes, `state` is the initial state of this store (default `{}`) `extensionId` is the extension id as defined by chrome when extension is loaded (default `''`)
* @param options An object of form {portName, state}, where `portName` is a required string and defines the name of the port for state transition changes and `state` is the initial state of this store (default `{}`)
*/
constructor(options?: {
portName?: string,
state?: any,
extensionId?: string,
serializer?: Function,
deserializer?: Function,
patchStrategy?: PatchStrategy
portName?: string;
state?: any;
serializer?: Function;
deserializer?: Function;
patchStrategy?: PatchStrategy;
});

/**
* Returns a promise that resolves when the store is ready.
* @return promise A promise that resolves when the store has established a connection with the background page.
*/
*/
ready(): Promise<void>;

/**
* Returns a promise that resolves when the store is ready.
* @param callback An callback that will fire when the store is ready.
* @return promise A promise that resolves when the store has established a connection with the background page.
*/
*/
ready<S>(cb: () => S): Promise<S>;

/**
* Subscribes a listener function for all state changes
* @param listener A listener function to be called when store state changes
* @return An unsubscribe function which can be called to remove the listener from state updates
*/
* Subscribes a listener function for all state changes
* @param listener A listener function to be called when store state changes
* @return An unsubscribe function which can be called to remove the listener from state updates
*/
subscribe(listener: () => void): () => void;

/**
Expand All @@ -49,7 +48,6 @@ export class Store<S = any, A extends redux.Action = redux.AnyAction> {
*/
patchState(difference: Array<any>): void;


/**
* Stub function to stay consistent with Redux Store API. No-op.
* @param nextReducer The reducer for the store to use instead.
Expand All @@ -65,7 +63,7 @@ export class Store<S = any, A extends redux.Action = redux.AnyAction> {
/**
* Dispatch an action to the background using messaging passing
* @param data The action data to dispatch
*
*
* Note: Although the return type is specified as the action, react-chrome-redux will
* wrap the result in a responsePromise that will resolve/reject based on the
* action response from the background page
Expand All @@ -78,22 +76,30 @@ export class Store<S = any, A extends redux.Action = redux.AnyAction> {
* For more information, see the observable proposal:
* https://github.com/tc39/proposal-observable
*/
[Symbol.observable](): Observable<S>
[Symbol.observable](): Observable<S>;
}

export function wrapStore<S, A extends redux.Action = redux.AnyAction>(
type WrapStore<S, A extends redux.Action = redux.AnyAction> = (
store: redux.Store<S, A>,
configuration?: {
portName?: string,
dispatchResponder?(dispatchResult: any, send: (response: any) => void): void,
serializer?: Function,
deserializer?: Function,
diffStrategy?: DiffStrategy
},
): void;
portName?: string;
dispatchResponder?(
dispatchResult: any,
send: (response: any) => void
): void;
serializer?: Function;
deserializer?: Function;
diffStrategy?: DiffStrategy;
}
) => void;

export function createWrapStore<
S,
A extends redux.Action = redux.AnyAction
>(): WrapStore<S, A>;

export function alias(aliases: {
[key: string]: (action: any) => any
[key: string]: (action: any) => any;
}): redux.Middleware;

export function applyMiddleware(
Expand All @@ -105,7 +111,7 @@ export function applyMiddleware(
* Function to remove listener added by `Store.subscribe()`.
*/
export interface Unsubscribe {
(): void
(): void;
}

/**
Expand All @@ -122,14 +128,14 @@ export type Observable<T> = {
* be used to unsubscribe the observable from the store, and prevent further
* emission of values from the observable.
*/
subscribe: (observer: Observer<T>) => { unsubscribe: Unsubscribe }
[Symbol.observable](): Observable<T>
}
subscribe: (observer: Observer<T>) => { unsubscribe: Unsubscribe };
[Symbol.observable](): Observable<T>;
};

/**
* An Observer is used to receive data from an Observable, and is supplied as
* an argument to subscribe.
*/
export type Observer<T> = {
next?(value: T): void
}
next?(value: T): void;
};
Loading
Loading