Version: v0.8.1 - Beta.  We welcome contributors & feedback.

ObjectHooks.onGetMissingField

onGetMissingField(fieldName) -> Result

Description

Add this method to your class to handle access to fields that are not publicly defined.

Return Result.ok($value) if the call was successful. Otherwise, return Result.fail() to trigger an error.

class Timer {

    fields {
        durationSecs: 600
    }

    fun onGetMissingField($fieldName) {
        if $fieldName == 'durationMins' {
            // convert seconds to minutes
            $durationMins = @.state.durationSecs / 60
            return Result.ok($durationMins)
        }
        return Result.fail()
    }
}

$timer = Timer()

$timer.durationMins  //= 10

See Also