@inglorious/store 7.1.0 → 7.1.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 +5 -4
- package/package.json +2 -2
- package/src/event-map.js +6 -5
- package/src/event-map.test.js +47 -0
package/README.md
CHANGED
|
@@ -831,10 +831,11 @@ Now, your store is fully type-safe. The hooks provided by `@inglorious/react-sto
|
|
|
831
831
|
|
|
832
832
|
Check out the following demos to see the Inglorious Store in action on real-case scenarios:
|
|
833
833
|
|
|
834
|
-
- **[TodoMVC](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/todomvc)** - An (ugly) clone of Kent Dodds' [TodoMVC](https://todomvc.com/) experiments, showing the full compatibility with react-redux and The Redux DevTools.
|
|
835
|
-
- **[TodoMVC-CS](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/todomvc-cs)** - A client-server version of the TodoMVC, which showcases the use of `notify` as a cleaner alternative to `dispatch` and async event handlers.
|
|
836
|
-
- **[TodoMVC-RT](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/todomvc-rt)** - A "multiplayer" version, in which multiple clients are able to synchronize through a real-time server.
|
|
837
|
-
- **[TodoMVC-TS](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/todomvc-ts)** - A typesafe version of the base TodoMVC.
|
|
834
|
+
- **[React TodoMVC](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/react-todomvc)** - An (ugly) clone of Kent Dodds' [TodoMVC](https://todomvc.com/) experiments, showing the full compatibility with react-redux and The Redux DevTools.
|
|
835
|
+
- **[React TodoMVC-CS](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/react-todomvc-cs)** - A client-server version of the TodoMVC, which showcases the use of `notify` as a cleaner alternative to `dispatch` and async event handlers.
|
|
836
|
+
- **[React TodoMVC-RT](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/react-todomvc-rt)** - A "multiplayer" version, in which multiple clients are able to synchronize through a real-time server.
|
|
837
|
+
- **[React TodoMVC-TS](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/react-todomvc-ts)** - A typesafe version of the base TodoMVC.
|
|
838
|
+
- **[Web TodoMVC](https://github.com/IngloriousCoderz/inglorious-engine/tree/main/examples/apps/web-todomvc)** - The same app, written with the [`@inglorious/web`](https://www.npmjs.com/package/@inglorious/web) framework instead of React.
|
|
838
839
|
|
|
839
840
|
---
|
|
840
841
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inglorious/store",
|
|
3
|
-
"version": "7.1.
|
|
3
|
+
"version": "7.1.2",
|
|
4
4
|
"description": "A state manager for real-time, collaborative apps, inspired by game development patterns and compatible with Redux.",
|
|
5
5
|
"author": "IceOnFire <antony.mistretta@gmail.com> (https://ingloriouscoderz.it)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"prettier": "^3.6.2",
|
|
59
59
|
"vite": "^7.1.3",
|
|
60
60
|
"vitest": "^1.6.1",
|
|
61
|
-
"@inglorious/eslint-config": "1.
|
|
61
|
+
"@inglorious/eslint-config": "1.1.1"
|
|
62
62
|
},
|
|
63
63
|
"engines": {
|
|
64
64
|
"node": ">= 22"
|
package/src/event-map.js
CHANGED
|
@@ -96,7 +96,8 @@ export class EventMap {
|
|
|
96
96
|
* Supports scoped events:
|
|
97
97
|
* - 'submit' -> all entities with 'submit' handler
|
|
98
98
|
* - 'form:submit' -> all form entities with 'submit' handler
|
|
99
|
-
* - 'form
|
|
99
|
+
* - 'form#loginForm:submit' -> only loginForm entity (of type form)
|
|
100
|
+
* - '#loginForm:submit' -> only loginForm entity
|
|
100
101
|
*
|
|
101
102
|
* @param {string} eventString - The event string (e.g., 'submit', 'form:submit', 'form[id]:submit')
|
|
102
103
|
* @returns {string[]} An array of entity IDs that should handle this event.
|
|
@@ -111,9 +112,9 @@ export class EventMap {
|
|
|
111
112
|
const typeMap = this.handlerToTypeToEntities.get(handlerName)
|
|
112
113
|
if (!typeMap) return []
|
|
113
114
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const entitySet = typeMap.get(
|
|
115
|
+
if (targetEntityId) {
|
|
116
|
+
const type = targetType ?? this.entityTypes.get(targetEntityId)
|
|
117
|
+
const entitySet = typeMap.get(type)
|
|
117
118
|
return entitySet && entitySet.has(targetEntityId) ? [targetEntityId] : []
|
|
118
119
|
}
|
|
119
120
|
|
|
@@ -134,7 +135,7 @@ export class EventMap {
|
|
|
134
135
|
|
|
135
136
|
/**
|
|
136
137
|
* Parses an event string into its components.
|
|
137
|
-
* @param {string} eventString - The event string (e.g., 'submit', 'form:submit', 'form
|
|
138
|
+
* @param {string} eventString - The event string (e.g., 'submit', 'form:submit', 'form#loginForm:submit')
|
|
138
139
|
* @returns {{ type: string|null, entityId: string|null, event: string }}
|
|
139
140
|
*/
|
|
140
141
|
export function parseEvent(eventString) {
|
package/src/event-map.test.js
CHANGED
|
@@ -109,6 +109,53 @@ test("getEntitiesForEvent should return the correct set of entities for an event
|
|
|
109
109
|
expect(fireEntities).toStrictEqual([])
|
|
110
110
|
})
|
|
111
111
|
|
|
112
|
+
test("getEntitiesForEvent should handle scoped events correctly", () => {
|
|
113
|
+
const types = {
|
|
114
|
+
form: { submit: () => {} },
|
|
115
|
+
button: { submit: () => {} },
|
|
116
|
+
}
|
|
117
|
+
const entities = {
|
|
118
|
+
loginForm: { type: "form" },
|
|
119
|
+
signupForm: { type: "form" },
|
|
120
|
+
submitButton: { type: "button" },
|
|
121
|
+
}
|
|
122
|
+
const eventMap = new EventMap(types, entities)
|
|
123
|
+
|
|
124
|
+
// Scoped to a type: 'form:submit' should only return form entities
|
|
125
|
+
expect(eventMap.getEntitiesForEvent("form:submit")).toStrictEqual([
|
|
126
|
+
"loginForm",
|
|
127
|
+
"signupForm",
|
|
128
|
+
])
|
|
129
|
+
|
|
130
|
+
// Scoped to a specific entity by ID: '#loginForm:submit'
|
|
131
|
+
expect(eventMap.getEntitiesForEvent("#loginForm:submit")).toStrictEqual([
|
|
132
|
+
"loginForm",
|
|
133
|
+
])
|
|
134
|
+
|
|
135
|
+
// Scoped to a specific entity by type and ID: 'form#loginForm:submit'
|
|
136
|
+
expect(eventMap.getEntitiesForEvent("form#loginForm:submit")).toStrictEqual([
|
|
137
|
+
"loginForm",
|
|
138
|
+
])
|
|
139
|
+
|
|
140
|
+
// Scoped to a non-existent entity ID
|
|
141
|
+
expect(eventMap.getEntitiesForEvent("#nonExistent:submit")).toStrictEqual([])
|
|
142
|
+
|
|
143
|
+
// Scoped to an entity that exists but doesn't handle the event
|
|
144
|
+
expect(eventMap.getEntitiesForEvent("#loginForm:click")).toStrictEqual([])
|
|
145
|
+
|
|
146
|
+
// Scoped to an entity ID, but with the wrong type specified
|
|
147
|
+
expect(eventMap.getEntitiesForEvent("button#loginForm:submit")).toStrictEqual(
|
|
148
|
+
[],
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
// Broadcast event should return all entities with the handler
|
|
152
|
+
expect(eventMap.getEntitiesForEvent("submit")).toStrictEqual([
|
|
153
|
+
"loginForm",
|
|
154
|
+
"signupForm",
|
|
155
|
+
"submitButton",
|
|
156
|
+
])
|
|
157
|
+
})
|
|
158
|
+
|
|
112
159
|
test("EventMap provides a significant performance benefit for event handling", async () => {
|
|
113
160
|
const ENTITY_COUNT = 10000
|
|
114
161
|
const { entities, types } = createTestEntities(ENTITY_COUNT)
|