@inglorious/store 11.0.4 → 11.0.5

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/types/store.d.ts +13 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/store",
3
- "version": "11.0.4",
3
+ "version": "11.0.5",
4
4
  "description": "A state manager for real-time, collaborative apps, inspired by game development patterns and compatible with Redux.",
5
5
  "author": "Matteo Antony Mistretta <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
6
6
  "license": "MIT",
@@ -62,7 +62,7 @@
62
62
  "@inglorious/utils": "5.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@inglorious/eslint-config": "1.1.2",
65
+ "@inglorious/eslint-config": "1.1.4",
66
66
  "@reduxjs/toolkit": "^2.12.0",
67
67
  "prettier": "^3.9.6",
68
68
  "vite": "^8.2.2",
package/types/store.d.ts CHANGED
@@ -25,9 +25,18 @@ export interface Event<T = any> {
25
25
  * off so that it stops.
26
26
  */
27
27
  export type EntityType<TEntity extends BaseEntity = BaseEntity> = {
28
- [K: string]: (entity: TEntity, payload: any, api: Api) => void
28
+ [K: string]: EventHandler<TEntity>
29
29
  }
30
30
 
31
+ /**
32
+ * A handler, checked as a method is: a type for a specific entity, such as
33
+ * `Api<AppEntity>`'s, then fits where `BaseEntity`'s is expected, so a component
34
+ * typed with the plain `Api` accepts an app's.
35
+ */
36
+ type EventHandler<TEntity extends BaseEntity> = {
37
+ bivarianceHack(entity: TEntity, payload: any, api: Api): void
38
+ }["bivarianceHack"]
39
+
31
40
  /**
32
41
  * System definition with event handlers
33
42
  */
@@ -78,7 +87,9 @@ export interface StoreConfig<
78
87
  TEntity extends BaseEntity = BaseEntity,
79
88
  TState extends EntitiesState<TEntity> = EntitiesState<TEntity>,
80
89
  > {
81
- types?: TypesConfig<TEntity>
90
+ // Types do not pick the entity type: their handlers accept any entity, so
91
+ // it comes from `entities`, `middlewares` or the explicit type arguments.
92
+ types?: TypesConfig<NoInfer<TEntity>>
82
93
  /** The initial entities. With `autoCreateEntities`, those the store creates itself can be left out. */
83
94
  entities?: Partial<TState>
84
95
  systems?: System<TState>[]