/// <summary> /// The javascript object window.sharpAngieBridge should be set up so that any call to sharpAngieBridge.initialize() will be forwarded to this method. /// </summary> /// <param name="clientId">User defined identifier for the client. Will be forwarded to IAngularInterface. can be null if not needed.</param> public void Initialize(string clientId) { var modelJson = JsonSerializer.SerializeToString(_viewModel); _angularInterface.SetModel(clientId, modelJson); ViewModelBase.DeepPropertyChangedEventHandler handler; if (string.IsNullOrEmpty(clientId) || !_propertyChangedEventHandlersByClient.TryGetValue(clientId, out handler)) { handler = (s, propertyPath, value) => { if (_currentClientId == clientId && _changingPropertyFromJs == propertyPath.Replace('[', '.').Replace("]", "")) { return; } var valueJson = value != null?JsonSerializer.SerializeToString(value) : null; _angularInterface.SetModelProperty(clientId, propertyPath, valueJson); }; if (!string.IsNullOrEmpty(clientId)) { _propertyChangedEventHandlersByClient.Add(clientId, handler); } } _viewModel.DeepPropertyChanged += handler; }