Single variant data constructor
Closed this issue · 2 comments
Many data declarations have a single constructor. Example:
const Disk = Data({
Disk: ['position', 'velocity', 'radius', 'item']
})
A shorthand should be provided:
const Disk = Data(['position', 'velocity', 'radius', 'item'])
A consequence of this is that the variants object that owns the collection no longer exists and the variant itself is anonymous behind the scenes (no way to assign the LHS name Disk
to [variantName]
).
This will impact Trait definitions:
const toString = Trait({
Disk: ({position, velocity, radius, item}) => `Disk(${position}, ${velocity}, ${radius}, ${item})`
})
'Disk' can't be looked up by [variantName]
as it's anonymous.
Trait
modifications required: move the inheritance concept into Trait instead of passing as a parameter:
const subTrait = Trait({
[extend]: baseTrait,
Foo: () => ...
})
Require a data declaration to be provided:
const subTrait = Trait(FooData, {
[extend]: baseTrait,
Foo: () => ...
})
FooData will be used to determine what functions must be provided. This will enable an early warning system
Instead of the [variantName]
system, update each data variant to have a constructor
reference.
Then add a reference to each trait function to the corresponding variant constructor.
When an instance is passed to a trait, compare references. This should enable the anonymous variant use case and also increase runtime performance as reference comparison is being used instead of string comparisons