Comments (5)
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.
Implemented in dd32e58
This is now available as release version 0.0.2.
from simpletwowaybindingios.
@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.
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.
Great!! 👍
from simpletwowaybindingios.
Related Issues (14)
- Observable doesn't support optional ObservedType HOT 1
- textField.observe has issues with cell reuse HOT 3
- Memory Leak? HOT 3
- Update to Swift 5 HOT 1
- issue on bindable func HOT 2
- UITextField and UITextView don't behave well with some unicode
- No exact matches in call to initializer
- How to bind tableview with any list
- What if i need to bind other properties on a UIControl? HOT 2
- What about UIImageView for example? HOT 3
- Unbind a control HOT 2
- Where is the model? HOT 1
- How would you change Bindable for NSControl?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from simpletwowaybindingios.