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 +28 -0
- package/dist/{chunk-GWGL3UX4.js → chunk-URTUZC7P.js} +551 -339
- package/dist/index.cjs +553 -339
- package/dist/index.d.cts +24 -3
- package/dist/index.d.ts +24 -3
- package/dist/index.js +5 -1
- package/dist/react.cjs +439 -770
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +4 -4
- package/dist/{types-ROPlWITM.d.cts → types-DOpAZa4-.d.cts} +88 -5
- package/dist/{types-ROPlWITM.d.ts → types-DOpAZa4-.d.ts} +88 -5
- package/package.json +2 -2
- package/react/index.cjs +439 -770
- package/react/index.d.cts +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +4 -4
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 `*`.
|