-
Notifications
You must be signed in to change notification settings - Fork 0
Models
To detect changes in an object the object has to be reactive. This ensures that we can display changes in this object. This is not a trivial task so there are drawbacks. In order to be convenient and counteract the drawbacks, we created many different forms of reactive objects so you can choose one for your applications. The functionality is the same for every approach.
A requirement for every single approach is encapsulation -> all fields/attributes are private.
If you are interested in how this was achieved: Technical details
This approach is for everyone who dislikes runtime reflection magic. Using ReactiveObjects is the most "Vanilla" like aproach.
Class:
public class Properties extends ReactiveObject {
private float volume;
public void setVolume(float value){
this.volume = volume;
react();
}
}Instance:
Properties props = new Properties();| Pro | Con |
|---|---|
| No Runtime generated classes |
extend is needed therefore no other class can be derived from |
You can define exactly when to update the ui (react call) |
You ** |
| have** to define when to update the ui | |
You can use new ()/the constructor to create objects |
Will just update the UI if you call a setter
|
This approach is for everyone who thinks convenience over convention. This approach is low effort
Class:
public class Properties implements ProxySubject {
private float volume;
//setters & getters not needed
}Instance Creation:
Properties props = ReactiveObject.create(Properties.class);Live Object Wrapping:
Properties props = new Properties();
Properties reactiveProperties = ReactiveObject.wrap(props);if Properties(String) is the only constuctor we need to pass a string to wrap the object. The value just needs to be valid there is no need of a "usefull". It just needs to pass the constructor without a
IllegalArgumentException
Properties props = new Properties("Name of properties");
Properties reactiveProperties = ReactiveObject.wrap(props,"");| Pro | Con |
|---|---|
| Beside the instantiation you have no restrictions at all | Uses Runtime generated classes |
| This design allows to extend from any class(more: inheritance) | implementing an interface without "using" or implementing it is uncommon |
You cannot use new to create instances of this class |
This approach is for everyone who doesn't likes that you can't affect when to update the UI with ProxySubjects
Class:
public class Properties {
private float volume;
//setters & getters not needed
}Instance creaton :
ReactiveProxy<Properties> propsProx = ReactiveObject.create(Properties.class);
Properties props = propsProx.getObject();
propsProx.setStrategy(REACT_ON_SETTER);//(optional)Live object wraping :
Properties props = new Properties();
Properties reactiveProperties = ReactiveObject.wrap(props);if Properties(String) is the only constuctor we need to pass a string to wrap the object. The value just needs to be valid there is no need of a "usefull". It just needs to pass the constructor without a
IllegalArgumentException
Properties props = new Properties("Name of properties");
ReactiveProxy<Properties> reactiveProperties = ReactiveObject.wrap(props,"");| Pro | Con |
|---|---|
| You can define all which methods cause a UI reaction | Uses Runtime generated classes |
| This design allows to extend from any class(more: inheritance) | Bulky instantiation |
| You end up with two objects that you need to keep both | |
You cannot use new to create instances of this class |
This is most used if you want to use classes from a lib where you have no control over the classes
to make them implement ProxySubject as this method works with any encapsulated class.
If you have no control over external classes you still want to display there are two mayor ways:
- Just use
ReactiveProxie - Create a
ProxySubjectlayer
In the end it is just an empty class that derives from the class you want to use reactive.
@ReactivResolution(DEEP)
public ReactivePropertie extends ThirdPartyClass implements Reactive Subject {}More info about @ReactivResolution see inheritance
To make the configuring of this classes easy we created a few annotations
Enables you to change the name of a variable for binding
@Reactive("vol");
private float volume;binder.bind("vol",....);Makes that calls to the annotated method trigger UI updates.
This will change the current functionality ofReactiveProxy#setStrategy(Strategy)and replaceReactiveProxy#reactTo(String...)
Acts as listener forward in ReactiveComponent and ReactiveView. This will be replaced
by @ReactiveListener
Examples in Components & Views
Used on class to define weither to just react to variables in the class itself, or to also make inherited field/attributes reactive.
@ReactivResolution(DEEP)
public ReactivePropertie extends ThirdPartyClass implements Reactive Subject {}Useful references
Models & Reactive Objects | Components & Views & Observers | Binding & Operations | Events