B4A Library Observable

Discussion in 'Additional libraries, classes and official updates' started by Informatix, Jul 3, 2018.

  1. Informatix

    Informatix Expert Licensed User

    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 activity 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 activity or sub 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.

    Attached Files:

    Last edited: Jul 12, 2018
    iz0ndg, ilan, Emme Developer and 35 others like this.
  2. fredo

    fredo Active Member Licensed User

    Wonderful. Just wow. Finally.
    Now I might start the next App with a MVVM approach.

    ilan and Informatix like this.
  3. Martin Larsen

    Martin Larsen Active Member Licensed User

    Sounds great! Looking forward to try it.
  4. Lello1964

    Lello1964 Member Licensed User

    Very, very good.

    Can have more example ?
  5. Informatix

    Informatix Expert Licensed User

    Do you have a specific need in mind ?
  6. Lello1964

    Lello1964 Member Licensed User

    for example a db editing:
    add new record, edit & save, erase, move top,next,prev,bottom..
  7. Informatix

    Informatix Expert Licensed User

    Did you see the DBFields demo? You can extend it with other queries (with INSERT or DELETE statement), however the additional work is more related to SQL than to the Observable library. In all cases, you have to notify the observers by setting the ID of ObservableFields. For example, if you add a DELETE button, you have to change the ID of ObservableFields after performing the removal query to display the previous or next record. If you add an INSERT button, you have to set the new ID to display the new record when the query is done.
    This lets me think I could add a new class to my library. Stay tuned...
  8. Informatix

    Informatix Expert Licensed User

    A new version is available. It adds three new classes (ObservableRecord, ObservableRecordSelection, ObservableShort) and a new demo (DBFields method #3) using an ObservableRecord.
    I don't think that querying/updating a SQlite database can be simpler than doing it with the new ObservableRecord. It can be bound to multiple views (one by field).
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice