bitECS could benefit from a symbol-keyed default initializer. I've implemented one in #172, if it's something you want to include. If not, feel free to close this issue and corresponding PR.
It has the following semantics:
import { $default, Default, addComponent, addEntity, createWorld } from 'bitECS'
const world = createWorld()
const eid = addEntity( world )
const MyComponent = {
x: [] as number[],
y: [] as number[],
[$default]( eid, { x = 1, y = 1 } = {}) {
MyComponent.x[ eid ] = x
MyComponent.y[ eid ] = y
}
}
addComponent( world, eid, MyComponent )
assert( MyComponent.x[ eid ] === 1 )
// or:
addComponent( world, eid, Default( MyComponent, { x: 42 }))
bitECS could benefit from a symbol-keyed default initializer. I've implemented one in #172, if it's something you want to include. If not, feel free to close this issue and corresponding PR.
It has the following semantics: