@tramvai/types-actions-state-context 2.108.0 → 2.109.0

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/lib/events.d.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import type { Reducer } from './state';
1
2
  export type Event<Payload = void> = {
2
3
  readonly type: string;
3
4
  readonly payload: Payload;
5
+ store?: Reducer<any, any>;
4
6
  };
5
7
  export type BaseEventCreator<Payload> = {
6
8
  getType(): string;
9
+ store?: Reducer<any, any>;
7
10
  };
8
11
  export type EmptyEventCreator = BaseEventCreator<void> & (() => Event<void>);
9
12
  export type EventCreator0<Payload> = BaseEventCreator<Payload> & (() => Event<Payload>);
@@ -27,3 +30,4 @@ export type AnyPayloadTransformer = PayloadTransformer0<any> | PayloadTransforme
27
30
  export type EventCreators = {
28
31
  [K: string]: AnyEventCreator;
29
32
  };
33
+ export declare const isEvent: (event: any) => event is Event<void>;
@@ -0,0 +1,5 @@
1
+ const isEvent = (event) => {
2
+ return typeof event === 'object' && typeof event.type === 'string';
3
+ };
4
+
5
+ export { isEvent };
package/lib/events.js ADDED
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const isEvent = (event) => {
6
+ return typeof event === 'object' && typeof event.type === 'string';
7
+ };
8
+
9
+ exports.isEvent = isEvent;
package/lib/index.es.js CHANGED
@@ -1 +1,2 @@
1
+ export { isEvent } from './events.es.js';
1
2
  export { ACTION_PARAMETERS } from './actions.es.js';
package/lib/index.js CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var events = require('./events.js');
5
6
  var actions = require('./actions.js');
6
7
 
7
8
 
8
9
 
10
+ exports.isEvent = events.isEvent;
9
11
  exports.ACTION_PARAMETERS = actions.ACTION_PARAMETERS;
package/lib/state.d.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import type { AnyEventCreator, EmptyEventCreator, EventCreator1, Event } from './events';
2
2
  import type { AnyAction, TramvaiAction } from './actions';
3
+ export type EmptyEventHandler<State> = (state: State) => State;
3
4
  export type EventHandler<State, Payload = void> = (state: State, payload: Payload) => State;
5
+ export type EventHandlersToEventCreators<State, Model extends {
6
+ [K: string]: EventHandler<State, any>;
7
+ }> = {
8
+ [K in keyof Model]: Model[K] extends EmptyEventHandler<State> ? EmptyEventCreator : Model[K] extends EventHandler<State, infer Payload> ? EventCreator1<Payload> : null;
9
+ };
4
10
  /**
5
11
  * @deprecated
6
12
  */
@@ -26,16 +32,18 @@ export interface ReduceBaseStore<State> {
26
32
  rehydrate(state: Partial<State> | void): void;
27
33
  handle(payload: any, eventName: string, meta?: any): any;
28
34
  }
29
- export interface Reducer<State, Name extends string = string> {
35
+ export interface Reducer<State, Name extends string = string, Events = any> {
30
36
  storeName: Name;
31
37
  handlers: Record<string, Function | string>;
38
+ events: Events;
32
39
  new (): ReduceBaseStore<State>;
33
40
  on<Payload>(event: AnyEventCreator<Payload> | string | Array<AnyEventCreator | string>, handler: EventHandler<State, Payload>): this;
41
+ /**
42
+ * @deprecated Use object initializer for the createReducer call to define events
43
+ */
34
44
  createEvents<Model extends {
35
45
  [K: string]: EventHandler<State, any>;
36
- }>(model: Model): {
37
- [K in keyof Model]: Model[K] extends EventHandler<State, void> ? EmptyEventCreator : Model[K] extends EventHandler<State, infer Payload> ? EventCreator1<Payload, Payload> : null;
38
- };
46
+ }>(model: Model): EventHandlersToEventCreators<State, Model>;
39
47
  }
40
48
  export type StoreInstance = InstanceType<StoreClass>;
41
49
  export interface GetState {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/types-actions-state-context",
3
- "version": "2.108.0",
3
+ "version": "2.109.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -17,6 +17,7 @@
17
17
  "watch": "tsc -w"
18
18
  },
19
19
  "dependencies": {
20
+ "node-abort-controller": "^3.0.1",
20
21
  "tslib": "^2.4.0"
21
22
  },
22
23
  "peerDependencies": {