sealcode / sealious

An extensible, declarative node framework
25 stars 2 forks source link

To consider: Field-type inheritance #209

Closed kuba-orlik closed 9 years ago

kuba-orlik commented 9 years ago

Perhaps a field-type should have the ability to work sort of as a subset of another field-type, e.g. one should be able to create a field-type that accepts only colors that are shades of red - in this case the field-type's isProperValue method would first ask the color field type if the provided new_value is a proper color value. Any thoughts?

arkadiusz-wieczorek commented 9 years ago

Do you think about this case?

kuba-orlik commented 9 years ago

Yeah, I think that the code for the "only red-shaded colors" field-type could look like:

var reddish_color = new Sealious.ChipTypes.FieldType({
    name: "reddish_color",
    inherit_from: "color",
    isProperValue: function(context, new_value){
        //...check the value for redness
    }
});

Any value provided for such field type would be first checked by color field-type's .isProperValue method, and just then by reddish_color's .isProperValue. Only value that is deemed proper by both of these methods is considered proper for fields of type reddish_color

What do you think?

arkadiusz-wieczorek commented 9 years ago

In my opinion isProperValue method should be execute once by new FieldType inherit from color. Unfortunately that isn't possible because developer must be know structure about default color.

Your idea is good solution. I can do it. Where should be prototype function for inheritance?

kuba-orlik commented 9 years ago

All the changes for inheritance were written during works on #206, so I'm closing this issue, as #206 branch is going to be merged soon, anyway.