A utility extension to observe changes to a field. It can be used to simply general tasks used in everyday projects like changing UI when API request is successful, filtering list items etc.
Update value of observable. Calls the
OnChangeevent with old a new value.
Get value of observable. Returns null if no value is set.
The event which is called after the change of the property is made. The value of the property has already been changed when this event is invoked.
Lets create a simple project that loads an html file using
Web component and displays it using a label. We will show
ProgressBar while data loads and a
Snackbar with retry button in case of an error.
- Lets start by creating a procedure that shows progressbar and hides other visible components.
- Next create a procedure
getDatathat gets the file from network.
- We have added two observables called
ErrorObservable. First one observes changes to data while the other observes changes to error. We can use the
OnChangeblocks from these observables tocperform different operations whenever data or error changes. When data changes, we will show data to the user & when error changes, we will show snackbar to the user.
- Next we will use
Web.GotTextevent to handle request result. If our request is successful, we will change the value of
DataObservableother we will change value of
- To handle timeout and other network error, we will add blocks given below.
- Finally to get data when screen starts or when user clicks on retry button, we will use following events.
- APK File: Observable.apk (5.2 MB)
- AIA File: ObservableSampleSimple.aia (42.5 KB)
- Advance Usage Sample: ObservableSampleAdvance.aia (233.5 KB)
- AIX File : com.dreamers.observablefield.aix (38.3 KB)
- Adds functionality to create a single observable field.