Code Monkey home page Code Monkey logo

Comments (5)

manishkkatoch avatar manishkkatoch commented on June 30, 2024 1

I can see one caveat in your solution: whenever a control binds to an observable, it will notify all observers it's value even though it is not changed. These are unnecessary invocations which we can avoid if we modify Bindable as:

public func bind(with observable: Observable<BindingType>) {
        if let _self = self as? UIControl {
            _self.addTarget(Selector, action: Selector{ self.valueChanged() }, for: [.editingChanged, .valueChanged])
        }
        self.binder = observable
        //addition here.
        if let val = observable.value {
            self.updateValue(with: val)
        }
        //addition end.
        self.observe(for: observable) { (value) in
            self.updateValue(with: value)
        }
    }

this will ensure that the Bindable control which is asking to bind with Observable updates if the observable already had a set value.

from simpletwowaybindingios.

manishkkatoch avatar manishkkatoch commented on June 30, 2024 1

Implemented in dd32e58
This is now available as release version 0.0.2.

from simpletwowaybindingios.

manishkkatoch avatar manishkkatoch commented on June 30, 2024

@AnnieNinaJoyceV sorry for a super delayed response. I was away on a vacation.
In my opinion, I would set up my data, separate from my setup of bindings. The ViewModel, in this case, is not a traditional view model. Its primary focus is to provide bindings and observables which can change at later stages. Hence in the example, I was visualizing it as:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationItem.title = "Survey Form"
        setupBindings()
        viewModel.companyName.value = "Something"
    }

However, I do see reason in your requirement. If you have an implementation please raise a pull request, else I will have this implemented in a day's time.

from simpletwowaybindingios.

AnnieNinaJoyceV avatar AnnieNinaJoyceV commented on June 30, 2024

Uhm no! As said in my first post, tweaking the bind function has it fixed.
I will wait for your implementation. Since, I am not very sure whether the tweaking is proper.
Hope you had a nice vacation!! 👍

from simpletwowaybindingios.

AnnieNinaJoyceV avatar AnnieNinaJoyceV commented on June 30, 2024

Great!! 👍

from simpletwowaybindingios.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.