-
-
Save psethi1984/51b22bde411cba00cc8f96a25bfbab5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private LiveDataService liveDataService; | |
private ObservableCollection<ProductOrder> _orders; | |
private void ServiceInit() | |
{ | |
base.ServiceInit(); | |
liveDataService.RegisterFor<ProductOrder>( | |
newOrder => | |
{ | |
_logService.Log("New order received"); | |
_orders.Add(newOrder); | |
RaisePropertyChanged(() => AllOrders); | |
}, | |
deletedOrder => | |
{ | |
_logService.Log("Order deleted"); | |
_orders.Remove(deletedOrder); | |
RaisePropertyChanged(() => AllOrders); | |
}, | |
error => | |
{ | |
_logService.Log("Service lost"); | |
HandleError(error); | |
}); | |
} | |
private void ServiceDeInit() | |
{ | |
liveDataService.DeRegisterFor<ProductOrder>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private LiveDataService liveDataService; | |
private CacheService cacheService; | |
private ObservableCollection<Product> _specialProducts; | |
private void ServiceInit() | |
{ | |
base.ServiceInit(); | |
liveDataService.RegisterFor<List<Product>>( | |
newProducts => { | |
_logService.Log("New specials received"); | |
_specialProducts = new ObservableCollection<Product>(newProducts); | |
RaisePropertyChanged(() => SpecialProducts); | |
}, | |
d => | |
{ | |
// Not required | |
}, | |
error => | |
{ | |
_logService.Log("Service lost"); | |
HandleError(error); | |
}) | |
.CacheBy(cacheService) // Retrieves data from cache if still valid | |
.Scope(DiscountedProducts); // DiscountedProducts is synchronisation scope with live data | |
} | |
private void ServiceDeInit() | |
{ | |
liveDataService.DeRegisterFor<List<Product>>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment