Breeze entity observables - how to relaibly access custom knockout functions? - breeze

I have defined some custom knockout observable functions as documented on the knockout site here: http://knockoutjs.com/documentation/fn.html. Breeze seems to be burying the custom functions deeper inside the object hierarchy. For instance ko.observable.fn.myCustomFunction ends up appearing at entity.someProperty.ko_proto.__ko_proto__.fn.myCustomFunction instead of at entity.someProperty.myCustomFunction as expected.
How can I reliably access my custom knockout functions on breeze entities?

You can solve the problem yourself on a spot basis, by attaching a custom function to entity.someProperty that delegates to entity.someProperty.ko_proto.__ko_proto__.fn....
I bet you have to attach the function for each instance of the entity. I think the best place to do this is in a custom EntityType initializer.
The Knockout documentation recommends that you use custom KO functions sparingly. It says so several times. So the proposed workaround should be only a minor inconvenience.

Related

Using BIND framework for two way data-binding in iOS

I'm trying to use BIND framework to bind a UITableView with UITextfield's which can edit the content.
I'm trying to achieve something very similar to how binding is done in Mac OSX. Bind a datasource with view, let the user make changes, on save the data is saved after validations.
Typically this is done by subscribing the delegate or observing the valueChanged event from textfield. I wanted to try out a new way to reduce this, that's how I came across BIND framework.
It encourages to use an MVVM framework, usually seen in .NET. Binding is as simple as mapping the keypath of model with the view component. But I'm finding it difficult to achieve to two way binding, from model to component and back.
BINDINGS(MHPersonNameViewModel,
BINDViewModel(name, ~>, textLabel.text),
BINDViewModel(ID, ~>, detailTextLabel.text),
nil);
Could anyone point me in the right direction.
This is a late answer, and not even really an answer to your question, but I hope it's still useful.
Take a look at https://github.com/mutech/aka-ios-beacon. This is a binding framework that integrates into Interface Builder and (by default) uses the view controller as root view model.
You don't have to write any code to initialize bindings. In your example, assuming that the view controller has (KVO compliant) properties "name" and "ID", you would just need to set the UILabel "text binding" properties to name and ID (you find the in the property panel in interface builder and enable bindings for the view controller (also in the properties panel).
And that should be all you have to do to establish bindings.
In versions up to 0.1.1 of AKABeacon, "enable bindings" is not yet there. In this case your view controller would have to inherit from AKAFormViewController.

Where to bind observable getters in Polymer

In Polymer.dart I'm aware that there are no strictly observable getters, and that instead we need to use bindProperty() (Soon to be onPropertyChange()) and notifyProperty() to simulate the same thing.
Looking through various code samples, I see some locations where this is added in to the constructor of the PolymerElement's class, and others where the binding happens in the created() method. Is there a preference as to where binding should occur? Are there any significant benefits or detriments on putting them in one of these areas or another?
Putting bindProperty into the constructor no longer works in polymer.dart >= 0.8. I am in the process of changing all my samples.
I am now using created as the location where I put my onPropertyChange or similar calls.

Do I have to extend CustomEvent for custom DOM events?

Upon reading this question I wondered if it is really needed to extend CustomEvent if you want to have custom DOM events in your application. Would it be possible to just extend Event or does CustomEvent serve a special purpose for technical reasons?
An example I was thinking of: a login component with 2 properties "username" and "password". I can imagine a LoginEvent with those two properties. I could either:
have the two properties as properties of the event class, in which case I don't need/use the detail of CustomEvent and hence may not need to extend CustomEvent.
pass them in as an array to the detail property of CustomEvent.
create a LoginParams object with the two properties and pass this in to the detail property of CustomEvent.
CustomEvent.detail is meant exactly for this, though the types must be passable to JS so there are some restrictions.
It'd be nice if you could extend CustomEvent, but that had similar issues as extending Element.

How to intercept dynamic methods of domain objects with AOP or some other way?

I would like to wrap Domain class's dynamic methods like save() get*() with an Around advice (possibly using Spring AOP). The idea is to intercept these methods and take the decision to apply them or not. As part of it I would also like to save the return value in case the method is executed.
This logic needs to be performed as part of a plugin so that existing source code is not affected. Any help in this regard is appreciated.

Using element to element binding in Silverlight 3?

I don't really see the need for element to element binding in Silverlight 3 if using MVVM. Won't having one property directly affect another proper cause that property to be untestable?
To me, it makes more sense to do a two way binding to a explicit property defined in the ViewModel.
I agree that the use of MVVM severely deflates the usefulness of element to element binding.
Still, if all you are doing is binding two elements using a ViewModel property... what can you test? You can test that setting a property in the ViewModel sends a PropertyChanged event... but thats about it. Only when something else cares about that value is it useful to test a property like that.
In the simple cases, I can see element2element binding being more efficient and less code.

Resources