Type-R icon indicating copy to clipboard operation
Type-R copied to clipboard

Calculated fields

Open manchuwook opened this issue 6 years ago • 2 comments

Given I create a new record with sub-records, how would I return calculated fields from the sub-record?

Record A Strength: { level: number } Record B: lift: number { A.Strength.level * 10 } Record C: punchBonus: number { A.Strength.level / 2 }

A.Strength.level: 10 A.B.lift: 100 A.C.punchBonus: 5

I'm a bit confused with the domain-specific language. I'm using typescript.

manchuwook avatar Sep 28 '19 17:09 manchuwook

May be, getOwner() method will help you https://volijs.github.io/Type-R/#attrdef-shared-recordorcollection-

Bolik avatar Sep 29 '19 21:09 Bolik

Where would I put getOwner()?

Record B: lift: number { getOwner().Strength.level * 10 }

Or does in go in value?

@type(B).value(x => getOwner().Strength.level * 10).as lift: Number;

manchuwook avatar Sep 30 '19 15:09 manchuwook