Skip to content

NonFunctional ViewModels OR ViewModels with lifecycle OR Better Two Way Binding Field #27

@manas-chaudhari

Description

@manas-chaudhari

Usecase:
Two Way binding is required
Value of the field needs to be updated from an observable.

As of now, two way binding has been implemented using vanilla ObservableField. Hence, it has no functionality to bind to an Observable. Hence, the only way is to subscribe to the observable externally. However, that requires knowledge about lifecycle.
Idea is to provide a bindingadapter: bind:lifecycle_to: @{vm}, between View and any instance of Connectable interface.

The adapter will add an AttachStateListener and invoke connect when the view is subscribed and unsubscribe when view is detached.

ViewModels can then implement connect method and do the subscriptions there.

Not Functional any more 😭

Of course, it would be ideal to find a way around this. Allowing subscriptions in ViewModels would make the pattern weak, as it won't enforce functionalness constraint.

As twowaybinding behaviour is analogous to BehaviourSubject, it can be used to allow creating ObservableFields from observables while still allowing two way binding. Need to think about all edge cases here. If this works, this would be the way to go.

Looking for other usecases

Although subject could solve the top usecase, there could be other usecases, where subscribing cannot be moved to binding layer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions