Annotation Interface Observable
Only one of the query or mutation method needs to be annotated with
this annotation if the other method follows the normal conventions. If
the other method does not conform to conventions, then you will need to
annotate the pair and specify a value for name()
.
The method should only invoked within the scope of a transaction. The mutation method requires that the transaction be READ_WRITE.
The method that is annotated with this annotation must also comply with the following constraints:
- Must not be annotated with any other arez annotation
- Must not be private
- Must not be static
- Must not be final
- May be abstract but if abstract then the paired setter or getter must also be abstract
- Must be accessible to the class annotated by the
ArezComponent
annotation.
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Set this to false if there is no setter method and the component is expected to useObservableValueRef
to indicate when value has changed.Indicate whether the generated component class should add a parameter to the constructor to initialize this property.Return the name of the ObservableValue relative to the component.Indicate whether the observable can be read outside a transaction.boolean
Return false if the setter should verify observable value has changed before propagating change.Return true if the observable will create an action if the write occurs outside a transaction.
-
Element Details
-
name
Return the name of the ObservableValue relative to the component. If not specified will default to the name of the property by convention as described above. The value must conform to the requirements of a java identifier. The name must also be unique acrossObservable
s,Memoize
s andAction
s within the scope of theArezComponent
annotated element.- Returns:
- the name of the ObservableValue relative to the component.
- Default:
- "<default>"
-
expectSetter
boolean expectSetterSet this to false if there is no setter method and the component is expected to useObservableValueRef
to indicate when value has changed.- Returns:
- true if there is expected to be a setter, false if there should be no setter.
- Default:
- true
-
initializer
Indicate whether the generated component class should add a parameter to the constructor to initialize this property. This parameter should only be set toFeature.ENABLE
when the observable property is defined by a pair of abstract methods. If set toFeature.AUTODETECT
then an initializer will be added for an observable property if it is defined by a pair of abstract methods and the values is annotated with theNonnull
annotation and it is not annotated byInverse
.The initializer parameters will be added as additional parameters at the end of the parameter list in the generated classes constructors. The initializers will be defined in the order that the observable properties are declared. They properties be assigned after the parent constructor has been invoked.
- Returns:
- flag controlling whether a parameter should be added to the constructor to initialize the property.
- Default:
- AUTODETECT
-
readOutsideTransaction
Indicate whether the observable can be read outside a transaction. If the value isFeature.AUTODETECT
then the value will be derived from theArezComponent.defaultReadOutsideTransaction()
parameter on theArezComponent
annotation. If the value is set toFeature.ENABLE
then the observable can be read outside a transaction and theObservableValue.reportObserved()
will only be invoked if the observables is accessed from within a tracking transaction (i.e. when anObserver
orComputableValue
creates the transaction). Thus,Action
annotated methods that only access observables that set the readOutsideTransaction parameter toFeature.ENABLE
and neither access nor modify other arez elements no longer need to be annotated withAction
annotations.- Returns:
- flag that determines whether the observable allows reads outside a transaction, false to require a transaction to read the observable.
- Default:
- AUTODETECT
-
writeOutsideTransaction
Return true if the observable will create an action if the write occurs outside a transaction.- Returns:
- true to allow writes to create an action if needed, false to require a transaction to write observable.
- Default:
- AUTODETECT
-
setterAlwaysMutates
boolean setterAlwaysMutatesReturn false if the setter should verify observable value has changed before propagating change. In some scenarios, the setter method will modify the value before updating the observable or may decide to abort the update. This setting will force the generated code to check the value of the observable property after the setter and only invokeObservableValue.reportChanged()
if a change has actually occurred.This parameter should not be set to false if the associated setter is abstract. It is also invalid to set this value to false if
expectSetter()
is false.- Returns:
- false if the setter should verify observable value has changed before propagating change.
- Default:
- true
-