Allow use of a read-only variable in static command bindings
See original GitHub issueSome time ago I’ve found myself in a situation where I wanted to update multiple viewmodel properties in one button click. I wanted to load both user information and a shopping cart content to fill the top panel of my page when a button is clicked. Let’s have a viewmodel:
public class ThePage
{
public ShopingCartViewModel ShoppingCart { get; set; }
public UserInfo { get; set; }
//...
}
Of course the viewmodel contains lots of other properties, and I don’t want to drag them all to the server side and back just because I need to update 2 properties… …so I used a service with contract like this:
public class PanelInfoDto{
public ShopingCartViewModel ShoppingCart { get; set; }
public UserInfo { get; set; }
}
public interface IPanelInfoService
{
ShopingCartViewModel GetShoppingCart();
UserInfo GetUserInfo();
PanelInfoDto GetPanelInfo();
}
I realized, that there is no practical way to update two properties at once using single service call inside of static command.
Only 2 ways to solve this now:
-
Using two calls:
staticCommand: ShoppingCart = service.GetShoppingCart(); UserInfo = service.GetUserInfo()
. This is less then ideal because I need to make 2 calls to the server which is slower. This method does not work for all cases. There are operations that require updating multiple properties which cannot be repeated (Save, Refresh of items,…). -
Using temporary viewmodel property:
staticCommand: Temp = service.GetPanelInfo(); UserInfo = Temp.UserInfo(); ShoppingCart = Temp.ShoppingCart
. This method also works for operations that cannot be repeated. However I find it clunky and hard on an unfamiliar reader.
My proposed solution:
<dot:Button Text="Update"
Click="{staticCommand: let info = service.GetPanelInfo();
UserInfo = info.UserInfo();
ShoppingCart = info.ShoppingCart}" />
Read-only binding local variable that would be defined in the first statement and could be used in all following statements in the same binding.
This variable would be also useful in following use cases:
- saving data and getting updated repeater items back together with success/error message
- updating 2 grids at once
- updating grid and filling items of dependent combo-boxes at the same time
- updating multiple filters that depend on each others values
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (12 by maintainers)
Top GitHub Comments
@martindybal This doesn’t support
Property.Property = something
, but instead of callingContext.UpdateProperties
we can return something likeViewModelPatch<T>
:And then call it like this:
We might also detect that we are adding or removing items from the collection and serialize the
ViewModelPatch
object so we can repeat the operation in JS.This was implemented in #869