B4J Library jObservable

Observables are primitive types (boolean, byte, double, float, integer, long, short), strings, objects or collections (map, list, record) that trigger events when they are modified. They can also automatically update the views with which they are bound.

Example 1: You have associated an ObservableString with all the OK buttons of your application. By changing the value of this Observable (e.g. ofConfirmButton.Value = "OK"), you change at the same time the label of all OK buttons, regardless of the module in which they are declared.

Example 2: In your application, you want to perform a task each time a list is modified by your code (e.g. saving the content to a file), regardless of the module in which that list is modified. By using an ObservableList, it becomes easy to perform the task according to the triggered event (Added, Cleared, Removed, Sorted, Updated).

Example 3: You have linked an ObservableField to a field in a database table. By changing the ID of this Observable, you get the value of the field corresponding to this ID and you trigger an Updated event. By changing the Observable value, you update the field in the database and trigger an Updated event.

Please note that this library is not based on the Observable class of Java. Its code is entirely written from scratch.

It exists a version for Android here.
 

Attachments

  • jObservable v1.1.zip
    76.7 KB · Views: 470

jmon

Well-Known Member
Licensed User
Longtime User
Thank you Informatix. That's a very useful library!

No, the project crashes.
It crashes in non-UI mode, but the same examples in UI mode work in DEBUG.

I systematically forget to add @RaiseSynchronousEvents in my Java libraries.
B4X:
#RaisesSynchronousEvents:omap_removed
#RaisesSynchronousEvents:omap_updated
#RaisesSynchronousEvents:ofkeyapple_updated
#RaisesSynchronousEvents:omap_added
#RaisesSynchronousEvents:omap_cleared
#RaisesSynchronousEvents:olist_updated
#RaisesSynchronousEvents:olist_removed
#RaisesSynchronousEvents:olist_sorted
#RaisesSynchronousEvents:offirstitem_updated
#RaisesSynchronousEvents:olist_added
#RaisesSynchronousEvents:olist_cleared
Weird that it works in UI but not in Non-UI. But adding the code above should fix the problem I guess
 
Last edited:
Top