Skip to content
This repository was archived by the owner on Apr 4, 2021. It is now read-only.

getter/setter per attribute #3

@soletan

Description

@soletan

As a developer
I would like to declare getter/setter
to control direct read/write access on attributes of a model.

Proposal:

exports.myAttribute = {
    type: "string",
    getter( raw ) {
        return someProcessing( raw );
    },
    setter( newValue, oldValue ) { 
        if ( !newValue ) {
            throw new TypeError( "missing actual value" );
        }

        return computedNewValue( newValue ); 
    },
};
  • Getters and setters are provided as declaration properties of an attribute.

  • They are supported without regards to the actual type of attribute.

  • Declaring either getter or setter should result in actual value accessible via getter/setter, only.

  • Declaring only getter or only setter should throw exception in case of using the lacking one by default.

  • Getters are invoked without any particular context (so it's ok to use arrow functions rather than requiring access to some particular context via this to work).

  • Getters are invoked with the attribute's current value as stored in backend.

  • Getters are designed to return the value as desired or throw exception in case of getting value is prohibited.

  • Setters are invoked without any particular context (so it's ok to use arrow functions rather than requiring access to some particular context via this to work).

  • Setters are invoked with attribute's new value to be and its current value to be replaced.

  • Setters are expected to return the eventually new value of attribute or throw exception in case of setting value is prohibited.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions