Settings
@Js
const class Settings : Obj, Dict
Settings wraps a dict that maps tags to statically typed fields for extension settings. To use this API:
- Create subclass of Settings
- Annotate const instance fields with @Setting
- Create constructor with Dict and it-block callback
The following coercions are supported:
- Int field from Number tag
- Duration field from Number tag
- Bool field from Marker tag
Example:
const class ExampleSettings : Settings
{
static new wrap(Dict d, |Str|? onErr := null) { create(ExampleRec#, d, onErr) }
new make(Dict d, |This| f) : super(d) { f(this) }
@Setting const Int limit := 99
@Setting const Duration timeout := 3sec
}
Sub constructor
Wrapped dict for this instance
Get a tag from wrapped dict
Return if wrapped dict is empty
Return if wrapped dict is missing given tag
Factory to create for given type and dict to wrap
Return if wrapped dict has given tag
Trap on the wrapped dict
Iterate the wrapped dict tags until callback returns non-null
Iterate the wrapped dict tags
static Settings create(Type type, Dict meta, |Str|? onErr)
Factory to create for given type and dict to wrap. Invalid tag values are logged to the given callback if provided.
virtual Void each(|Obj,Str| f)
Iterate the wrapped dict tags
virtual Obj? eachWhile(|Obj,Str->Obj?| f)
Iterate the wrapped dict tags until callback returns non-null
@Operator
virtual Obj? get(Str n)
Get a tag from wrapped dict
virtual Bool has(Str n)
Return if wrapped dict has given tag
virtual Bool isEmpty()
Return if wrapped dict is empty
new make(Dict meta)
Sub constructor.
Dict meta()
Wrapped dict for this instance
virtual Bool missing(Str n)
Return if wrapped dict is missing given tag
virtual Obj? trap(Str n, Obj?[]? a)
Trap on the wrapped dict