@inglorious/store 7.1.2 → 7.1.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/README.md CHANGED
@@ -831,17 +831,16 @@ 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
- - **[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.
834
+ **React Examples:**
839
835
 
840
- ---
836
+ - **[React TodoMVC](https://github.com/IngloriousCoderz/inglorious-forge/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.
837
+ - **[React TodoMVC-CS](https://github.com/IngloriousCoderz/inglorious-forge/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.
838
+ - **[React TodoMVC-RT](https://github.com/IngloriousCoderz/inglorious-forge/tree/main/examples/apps/react-todomvc-rt)** - A "multiplayer" version, in which multiple clients are able to synchronize through a real-time server.
839
+ - **[React TodoMVC-TS](https://github.com/IngloriousCoderz/inglorious-forge/tree/main/examples/apps/react-todomvc-ts)** - A typesafe version of the base TodoMVC.
841
840
 
842
- ## Part of the Inglorious Engine
841
+ For more demos and examples with `@inglorious/web`, see the [`@inglorious/web` README](../web/README.md).
843
842
 
844
- This store powers the [Inglorious Engine](https://github.com/IngloriousCoderz/inglorious-engine), a functional game engine. The same patterns that power games power your web apps.
843
+ ---
845
844
 
846
845
  ## Frequently Unsolicited Complaints (FUCs)
847
846
 
@@ -867,7 +866,7 @@ It looks like it's not, and that's a feature. If you're used to classes and inst
867
866
 
868
867
  **"This is not Data-Oriented Design."**
869
868
 
870
- It's not. Please grep this README and count how many occurrences of DoD you can find. This is not [Data-Oriented Design](https://en.wikipedia.org/wiki/Data-oriented_design), which is related to low-level CPU cache optimization. It's more similar to [Data-Driven Programming](https://en.wikipedia.org/wiki/Data-driven_programming), which is related to separating data and behavior. The Inglorious Engine separates behavior in... behaviors (grouped into so-called types), while the data is stored in plain objects called entities.
869
+ It's not. Please grep this README and count how many occurrences of DoD you can find. This is not [Data-Oriented Design](https://en.wikipedia.org/wiki/Data-oriented_design), which is related to low-level CPU cache optimization. It's more similar to [Data-Driven Programming](https://en.wikipedia.org/wiki/Data-driven_programming), which is related to separating data and behavior. The Inglorious Store separates behavior in... behaviors (grouped into so-called types), while the data is stored in plain objects called entities.
871
870
 
872
871
  ---
873
872
 
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@inglorious/store",
3
- "version": "7.1.2",
3
+ "version": "7.1.4",
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",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/IngloriousCoderz/inglorious-engine.git",
9
+ "url": "git+https://github.com/IngloriousCoderz/inglorious-forge.git",
10
10
  "directory": "packages/store"
11
11
  },
12
12
  "homepage": "https://inglorious-engine.vercel.app/",
13
13
  "bugs": {
14
- "url": "https://github.com/IngloriousCoderz/inglorious-engine/issues"
14
+ "url": "https://github.com/IngloriousCoderz/inglorious-forge/issues"
15
15
  },
16
16
  "keywords": [
17
17
  "state",
@@ -5,7 +5,7 @@ const LAST_STATE = 1
5
5
  // HMR-safe container to persist a single DevTools connection across Vite reloads.
6
6
  // Uses import.meta.hot.data when available (preferred), falls back to module scope.
7
7
  const globalContainer = import.meta.hot
8
- ? (import.meta.hot.data.__INGLORIOUS_DEVTOOLS__ ??= {})
8
+ ? ((import.meta.hot.data ??= {}).__INGLORIOUS_DEVTOOLS__ ??= {})
9
9
  : {}
10
10
 
11
11
  // connection shape: {
package/src/store.js CHANGED
@@ -17,12 +17,12 @@ import { augmentType, augmentTypes } from "./types.js"
17
17
  * @returns {Object} The store with methods to interact with state and events.
18
18
  */
19
19
  export function createStore({
20
- types: originalTypes,
21
- entities: originalEntities,
20
+ types: originalTypes = {},
21
+ entities: originalEntities = {},
22
22
  systems = [],
23
23
  middlewares = [],
24
24
  updateMode = "auto",
25
- }) {
25
+ } = {}) {
26
26
  const listeners = new Set()
27
27
 
28
28
  const types = augmentTypes(originalTypes)
@@ -90,18 +90,20 @@ export function createStore({
90
90
 
91
91
  // Handle special system events
92
92
  if (event.type === "morph") {
93
- const { id, type } = event.payload
93
+ const { name, type } = event.payload
94
94
 
95
- const entity = draft[id]
96
- const oldType = types[entity.type]
97
- const oldTypeName = entity.type
95
+ const oldType = types[name]
98
96
 
99
- originalTypes[entity.type] = type
100
- types[entity.type] = augmentType(originalTypes[entity.type])
101
- const newType = types[entity.type]
97
+ originalTypes[name] = type
98
+ types[name] = augmentType(type)
99
+ const newType = types[name]
102
100
 
103
- eventMap.removeEntity(id, oldType, oldTypeName)
104
- eventMap.addEntity(id, newType, oldTypeName) // Use the original type name
101
+ for (const [id, entity] of Object.entries(draft)) {
102
+ if (entity.type === name) {
103
+ eventMap.removeEntity(id, oldType, name)
104
+ eventMap.addEntity(id, newType, name)
105
+ }
106
+ }
105
107
  continue
106
108
  }
107
109
 
package/src/store.test.js CHANGED
@@ -169,7 +169,7 @@ test("it should change an entity's behavior via a 'morph' event", () => {
169
169
  bug: { id: "bug", type: "bug", isFull: true },
170
170
  })
171
171
 
172
- store.notify("morph", { id: "bug", type: [Caterpillar, Butterfly] })
172
+ store.notify("morph", { name: "bug", type: [Caterpillar, Butterfly] })
173
173
  store.notify("fly")
174
174
  store.update()
175
175
  expect(store.getState()).toStrictEqual({