malomalo / viking

Viking.js
vikingjs.org
MIT License
4 stars 5 forks source link

add support for records schema to have a function for type #97

Open bemky opened 2 years ago

bemky commented 2 years ago

Add support for record to have a dynamic type for an attribute

class Trait extends VikingRecord {
    static schema = {
        value_type: {type: "string"},
        value: {
            type: {
                load: (value, attrs) => Types.registry[attrs.value_type].load(value),
                dump: (value, attrs) => Types.registry[attrs.value_type].dump(value)
            }
        }
    }
}