@player-devtools/plugin 0.13.1--canary.13.739 → 0.13.1--canary.16.915

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/state.ts DELETED
@@ -1,43 +0,0 @@
1
- export type Reducer<T, A> = (state: T, action: A) => T;
2
- export type Dispatch<A> = (action: A) => void;
3
- export type Subscriber<T> = (state: T) => void;
4
- export type Subscribe<T> = (subscriber: Subscriber<T>) => Unsubscribe;
5
- export type Unsubscribe = () => void;
6
-
7
- export interface Store<State, Action> {
8
- getState: () => State;
9
- subscribe: Subscribe<State>;
10
- dispatch: Dispatch<Action>;
11
- }
12
-
13
- export const useStateReducer = <State, Action>(
14
- reducer: Reducer<State, Action>,
15
- initialState: State,
16
- ): Store<State, Action> => {
17
- let state = initialState;
18
- const subscribers = new Set<Subscriber<State>>();
19
- return {
20
- getState: () => state,
21
-
22
- /** Subscribe to state changes; returns an unsubscribe function. */
23
- subscribe(subscriber: Subscriber<State>): Unsubscribe {
24
- subscribers.add(subscriber);
25
- subscriber(state);
26
- return () => subscribers.delete(subscriber);
27
- },
28
-
29
- /** Dispatch an action through the reducer, then run side-effects. */
30
- dispatch(action: Action): void {
31
- const prevState = state;
32
- const nextState = reducer(prevState, action);
33
-
34
- // Only proceed if state actually changed by reference
35
- if (nextState !== prevState) {
36
- state = nextState;
37
-
38
- // Notify subscribers
39
- for (const sub of subscribers) sub(state);
40
- }
41
- },
42
- };
43
- };
package/types/state.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export type Reducer<T, A> = (state: T, action: A) => T;
2
- export type Dispatch<A> = (action: A) => void;
3
- export type Subscriber<T> = (state: T) => void;
4
- export type Subscribe<T> = (subscriber: Subscriber<T>) => Unsubscribe;
5
- export type Unsubscribe = () => void;
6
- export interface Store<State, Action> {
7
- getState: () => State;
8
- subscribe: Subscribe<State>;
9
- dispatch: Dispatch<Action>;
10
- }
11
- export declare const useStateReducer: <State, Action>(reducer: Reducer<State, Action>, initialState: State) => Store<State, Action>;
12
- //# sourceMappingURL=state.d.ts.map