Wednesday, October 09, 2013

Changes to custom bindings in v3.0.13

3.0.13 does include some breaking changes as we've changed some underlying APIs for custom bindings.

Sorry for this - these type of API changes are something we try to avoid - but in this case there were some good reasons.

We've changed the API for two key reasons:

  1. Improved Performance - we've found that by splitting the target binding event subscription out into a separate public API then we can achieve better binding performance for OneWay bindings
  2. Improved Functionality - we've identified that more bindings can benefit from auto-type coercion and from auto-change-loop removal by moving the SetValue helpers from the PropertyInfo-based bindings to a lower level.

With those justifications out of the way, the key changes you should make to any custom binding in v3.0.13 or later are:

Move event subscriptions into SubscribeToEvents

This isn't essential - but is good practice. If the user specifies OneWay binding, then this change will provide them with a small performance improvement with each binding.

Code before change:

Code after change:

Move value setting code from SetValue into SetValueImpl

This change is essential.With this change, then the MvvmCross base classes will provide additional type coercion for you (e.g. MvvmCross will automatically convert strings to ints)

Without it, you will get a compiler error saying: "Error 3 'YourTargetBinding' does not implement inherited abstract member 'MvxConvertingTargetBinding.SetValueImpl(object, object)'

Code before change:

Code after change:

Sorry again for any inconvenience caused by this change - we've tried very hard not to make breaking changes to APIs since we signed the v3 APIs off on March 1st this year - but in this case the benefits were worth it!

No comments:

Post a Comment