@inglorious/store 4.0.0 → 4.0.2
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/README.md +1 -1
- package/package.json +8 -4
- package/src/store.js +11 -7
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ The state management is built on a few simple principles:
|
|
|
31
31
|
- The store processes events by first applying behaviors defined on an entity's type, and then running the logic in the systems.
|
|
32
32
|
- An `update` event with a `dt` (delta time) payload is automatically dispatched on every `store.update()` call, making it suitable for a game loop.
|
|
33
33
|
|
|
34
|
-
4. **Immutability**: The state is immutable. Updates are handled internally by **[
|
|
34
|
+
4. **Immutability**: The state is immutable. Updates are handled internally by **[Mutative](https://mutative.js.org/)**, so you can "mutate" the state directly within a type's or system's behavior function, and a new, immutable state will be created.
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/store",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "A state manager inspired by Redux, but tailored for the specific needs of game development.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,13 +33,17 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"
|
|
37
|
-
"@inglorious/utils": "3.
|
|
36
|
+
"mutative": "^1.3.0",
|
|
37
|
+
"@inglorious/utils": "3.5.0"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@inglorious/utils": "3.5.0"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"prettier": "^3.6.2",
|
|
41
44
|
"vite": "^7.1.3",
|
|
42
|
-
"vitest": "^1.6.1"
|
|
45
|
+
"vitest": "^1.6.1",
|
|
46
|
+
"@inglorious/eslint-config": "1.0.0"
|
|
43
47
|
},
|
|
44
48
|
"engines": {
|
|
45
49
|
"node": ">= 22"
|
package/src/store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { create } from "mutative"
|
|
2
2
|
|
|
3
3
|
import { createApi } from "./api.js"
|
|
4
4
|
import { augmentEntities, augmentEntity } from "./entities.js"
|
|
@@ -67,7 +67,15 @@ export function createStore({
|
|
|
67
67
|
function update() {
|
|
68
68
|
const processedEvents = []
|
|
69
69
|
|
|
70
|
-
state =
|
|
70
|
+
state = create(state, patcher, {
|
|
71
|
+
enableAutoFreeze: state.entities.game?.devMode,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
listeners.forEach((onUpdate) => onUpdate())
|
|
75
|
+
|
|
76
|
+
return processedEvents
|
|
77
|
+
|
|
78
|
+
function patcher(draft) {
|
|
71
79
|
while (incomingEvents.length) {
|
|
72
80
|
const event = incomingEvents.shift()
|
|
73
81
|
processedEvents.push(event)
|
|
@@ -118,11 +126,7 @@ export function createStore({
|
|
|
118
126
|
handle?.(draft, event.payload, api)
|
|
119
127
|
})
|
|
120
128
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
listeners.forEach((onUpdate) => onUpdate())
|
|
124
|
-
|
|
125
|
-
return processedEvents
|
|
129
|
+
}
|
|
126
130
|
}
|
|
127
131
|
|
|
128
132
|
/**
|