mlhaufe / brevity

Brevity is a library that enables Feature-Oriented Programming (FOP) and solves the expression problem in a manner that makes data and operation declarations trivial to define and compose.
GNU Affero General Public License v3.0
1 stars 0 forks source link

Fix subtyping relationship in extended data #56

Closed mlhaufe closed 1 year ago

mlhaufe commented 1 year ago
const fooData = data({ Foo: {}, ... })

const barData = data({ [extend]: fooData, Bar: {}, ... })

barData[baseVariant] === fooData

This should be equal to barData. The issue and challenge is here:

// data.mjs

factory = dataDef[extend] ? Object.create(dataDef[extend]) :
    Object.assign(Object.create(protoFactory), { [baseVariant]: protoVariant })

Ideally, the fix would just be:

factory = Object.assign(Object.create(dataDef[extend] ?? protoFactory), {
    [baseVariant]: protoVariant
})

But dataDef[extend] is frozen.

mlhaufe commented 1 year ago

Fixed as part of #63