@inglorious/store 7.1.4 → 8.0.0

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
@@ -367,18 +367,16 @@ Inglorious Store has a few built-in events that you can use:
367
367
 
368
368
  The lifecycle events can be used to define event handlers similar to constructor and destructor methods in OOP:
369
369
 
370
- > Remember: events are broadcast to all entities, just like with reducers! Each handler decides if it should respond. More on that in the section below.
370
+ > Note: these special lifecycle events are not broadcast: they are visible only to the added/removed entity!
371
371
 
372
372
  ```javascript
373
373
  const types = {
374
374
  counter: {
375
- create(entity, id) {
376
- if (entity.id !== id) return // "are you talking to me?"
375
+ create(entity) {
377
376
  entity.createdAt = Date.now()
378
377
  },
379
378
 
380
- destroy(entity, id) {
381
- if (entity.id !== id) return // "are you talking to me?"
379
+ destroy(entity) {
382
380
  entity.destroyedAt = Date.now()
383
381
  },
384
382
  },
@@ -721,11 +719,11 @@ Each handler receives three arguments:
721
719
  - `getTypes()` - type definitions (for middleware)
722
720
  - `getType(typeName)` - type definition (for overriding)
723
721
 
724
- ### Built-in Lifecycle Events
722
+ ### Built-in Events
725
723
 
726
- - **`create(entity, id)`** - triggered when entity added via `add` event
727
- - **`destroy(entity, id)`** - triggered when entity removed via `remove` event
728
- - **`morph(entity, newType)`** - triggered when entity type changes
724
+ - **`create(entity)`** - triggered when entity added via `add` event, visible only to that entity
725
+ - **`destroy(entity)`** - triggered when entity removed via `remove` event, visible only to that entity
726
+ - **`morph(typeName, newType)`** - used to change the behavior of a type on the fly
729
727
 
730
728
  ### Notify vs Dispatch
731
729
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inglorious/store",
3
- "version": "7.1.4",
3
+ "version": "8.0.0",
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",
package/src/store.js CHANGED
@@ -113,7 +113,7 @@ export function createStore({
113
113
  const type = types[entity.type]
114
114
 
115
115
  eventMap.addEntity(id, type, entity.type)
116
- incomingEvents.unshift({ type: "create", payload: id })
116
+ incomingEvents.unshift({ type: `#${id}:create` })
117
117
  continue
118
118
  }
119
119
 
@@ -125,7 +125,7 @@ export function createStore({
125
125
  delete draft[id]
126
126
 
127
127
  eventMap.removeEntity(id, type, typeName)
128
- incomingEvents.unshift({ type: "destroy", payload: id })
128
+ incomingEvents.unshift({ type: `#${id}:destroy` })
129
129
  continue
130
130
  }
131
131
 
@@ -233,11 +233,11 @@ export function createStore({
233
233
  )
234
234
 
235
235
  entitiesToCreate.forEach((id) => {
236
- incomingEvents.push({ type: "create", payload: id })
236
+ incomingEvents.push({ type: `#${id}:create` })
237
237
  })
238
238
 
239
239
  entitiesToDestroy.forEach((id) => {
240
- incomingEvents.push({ type: "destroy", payload: id })
240
+ incomingEvents.push({ type: `#${id}:destroy` })
241
241
  })
242
242
  }
243
243