koota 0.6.1 → 0.6.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 CHANGED
@@ -201,6 +201,34 @@ hero.has(Targeting(rat)) // False
201
201
  hero.has(Targeting(goblin)) // True
202
202
  ```
203
203
 
204
+ #### Ordered relations
205
+
206
+ > ⚠️ **Experimental**<br>
207
+ > This API is experimental and may change in future versions. Please provide feedback on GitHub or Discord.
208
+
209
+ Ordered relations maintain a list of related entities with bidirectional sync.
210
+
211
+ ```js
212
+ import { relation, ordered } from 'koota'
213
+
214
+ const ChildOf = relation()
215
+ const OrderedChildren = ordered(ChildOf)
216
+
217
+ const parent = world.spawn(OrderedChildren)
218
+ const children = parent.get(OrderedChildren)
219
+
220
+ children.push(child1) // adds ChildOf(parent) to child1
221
+ children.splice(0, 1) // removes ChildOf(parent) from child1
222
+
223
+ // Bidirectional sync works both ways
224
+ child2.add(ChildOf(parent)) // child2 automatically added to list
225
+ ```
226
+
227
+ Ordered relations support array methods like `push()`, `pop()`, `shift()`, `unshift()`, and `splice()`, plus special methods `moveTo()` and `insert()` for precise control. Changes to the list automatically sync with relations, and vice versa.
228
+
229
+ > ⚠️ **Performance note**<br>
230
+ > Ordered relations are more expensive to update than regular relations but enable faster traversal when order matters. Use them only when entity order is essential.
231
+
204
232
  #### Querying relations
205
233
 
206
234
  Relations can be queried with specific targets and wildcard targets using `*`.