@inglorious/store 11.0.3 → 11.0.4
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/package.json +1 -1
- package/src/store.js +8 -1
- package/types/api.d.ts +5 -1
- package/types/store.d.ts +6 -2
- package/types/test.d.ts +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/store",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.4",
|
|
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",
|
package/src/store.js
CHANGED
|
@@ -332,7 +332,10 @@ export function createStore({
|
|
|
332
332
|
}
|
|
333
333
|
|
|
334
334
|
/**
|
|
335
|
-
* Sets an augmented type configuration given its name.
|
|
335
|
+
* Sets an augmented type configuration given its name. Replacing a type, as
|
|
336
|
+
* hot module reloading does, notifies subscribers, since what its entities
|
|
337
|
+
* render may have changed. Adding a type does not: the store is unchanged,
|
|
338
|
+
* and a type can be added while rendering.
|
|
336
339
|
* @param {string} typeName - The name of the type to set.
|
|
337
340
|
* @param {Type} type - The type configuration.
|
|
338
341
|
* @returns {void}
|
|
@@ -358,6 +361,10 @@ export function createStore({
|
|
|
358
361
|
type: typeName,
|
|
359
362
|
})
|
|
360
363
|
}
|
|
364
|
+
|
|
365
|
+
if (oldType) {
|
|
366
|
+
listeners.forEach((onUpdate) => onUpdate())
|
|
367
|
+
}
|
|
361
368
|
}
|
|
362
369
|
|
|
363
370
|
/**
|
package/types/api.d.ts
CHANGED
|
@@ -21,7 +21,11 @@ export interface Api<
|
|
|
21
21
|
(): TState
|
|
22
22
|
(typeName: string): TEntity[]
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
/** A known id gives that entity's own type; any other id, the union. */
|
|
25
|
+
getEntity: {
|
|
26
|
+
<TId extends keyof TState & string>(id: TId): TState[TId] | undefined
|
|
27
|
+
(id: string): TEntity | undefined
|
|
28
|
+
}
|
|
25
29
|
select: <TResult>(selector: (state: TState) => TResult) => TResult
|
|
26
30
|
dispatch: (event: Event) => void
|
|
27
31
|
notify: (type: string, payload?: any) => void
|
package/types/store.d.ts
CHANGED
|
@@ -79,7 +79,8 @@ export interface StoreConfig<
|
|
|
79
79
|
TState extends EntitiesState<TEntity> = EntitiesState<TEntity>,
|
|
80
80
|
> {
|
|
81
81
|
types?: TypesConfig<TEntity>
|
|
82
|
-
entities
|
|
82
|
+
/** The initial entities. With `autoCreateEntities`, those the store creates itself can be left out. */
|
|
83
|
+
entities?: Partial<TState>
|
|
83
84
|
systems?: System<TState>[]
|
|
84
85
|
middlewares?: Middleware<TEntity, TState>[]
|
|
85
86
|
autoCreateEntities?: boolean
|
|
@@ -112,7 +113,10 @@ export interface Store<
|
|
|
112
113
|
getType: (typeName: string) => EntityType<TEntity>
|
|
113
114
|
setType: (typeName: string, type: EntityType<TEntity>) => void
|
|
114
115
|
getState: () => TState
|
|
115
|
-
getEntity:
|
|
116
|
+
getEntity: {
|
|
117
|
+
<TId extends keyof TState & string>(id: TId): TState[TId] | undefined
|
|
118
|
+
(id: string): TState[string] | undefined
|
|
119
|
+
}
|
|
116
120
|
setState: (nextState: TState) => void
|
|
117
121
|
reset: () => void
|
|
118
122
|
_api?: Api<TEntity, TState>
|
package/types/test.d.ts
CHANGED
|
@@ -11,7 +11,10 @@ export interface MockApi<
|
|
|
11
11
|
(): TState
|
|
12
12
|
(typeName: string): TEntity[]
|
|
13
13
|
}
|
|
14
|
-
getEntity:
|
|
14
|
+
getEntity: {
|
|
15
|
+
<TId extends keyof TState & string>(id: TId): TState[TId] | undefined
|
|
16
|
+
(id: string): TEntity | undefined
|
|
17
|
+
}
|
|
15
18
|
select: <TResult>(selector: (state: TState) => TResult) => TResult
|
|
16
19
|
dispatch: (event: Event) => void
|
|
17
20
|
notify: (type: string, payload?: any) => void
|