public GetCached ( object key ) : IJSCSGlue | ||
key | object | |
Résultat | IJSCSGlue |
private async void CSharpPropertyChanged(object sender, PropertyChangedEventArgs e) { var pn = e.PropertyName; var propertyAccessor = new PropertyAccessor(sender, pn, _Logger); if (!propertyAccessor.IsGettable) { return; } var currentfather = _SessionCache.GetCached(sender) as JsGenericObject; if (currentfather == null) { return; } var nv = propertyAccessor.Get(); var oldbridgedchild = currentfather.Attributes[pn]; if (Object.Equals(nv, oldbridgedchild.CValue)) { return; } await RegisterAndDo(() => _JSObjectBuilder.UnsafelMap(nv), (child) => currentfather.ReRoot(pn, child)); }
public async void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue) { try { var res = _SessionCache.GetCached(objectchanged) as JsGenericObject; if (res == null) { return; } var propertyAccessor = new PropertyAccessor(res.CValue, propertyName, _Logger); if (!propertyAccessor.IsSettable) { _Logger.Info(() => $"Unable to set C# from javascript object: property: {propertyName} is readonly."); return; } var targetType = propertyAccessor.GetTargetType(); var glue = GetCachedOrCreateBasic(newValue, targetType); var bridgeUpdater = glue.IsBasicNotNull() ? null : new BridgeUpdater(); await Context.RunOnUIContextAsync(() => { using (var relisten = glue.IsBasicNotNull() ? null : ReListen(bridgeUpdater)) using (_IsListening ? _ListenerRegister.GetPropertySilenter(res.CValue) : null) { var oldValue = propertyAccessor.Get(); propertyAccessor.Set(glue.CValue); var actualValue = propertyAccessor.Get(); if (Object.Equals(actualValue, glue.CValue)) { res.UpdateGlueProperty(propertyName, glue); return; } if (!Object.Equals(oldValue, actualValue)) { CSharpPropertyChanged(res.CValue, new PropertyChangedEventArgs(propertyName)); } } }); if (!(bridgeUpdater?.HasUpdatesOnJavascriptContext == true)) { return; } await Context.RunOnJavascriptContextAsync(() => { bridgeUpdater.UpdateOnJavascriptContext(Context.ViewModelUpdater); }); } catch (Exception e) { _Logger.Error(() => $"Unable to update ViewModel from View, exception raised: {e.Message}"); } }
public async void OnJavaScriptObjectChanges(IJavascriptObject objectchanged, string propertyName, IJavascriptObject newValue) { try { var currentfather = _SessionCache.GetCached(objectchanged) as JsGenericObject; if (currentfather == null) { return; } var propertyUpdater = currentfather.GetPropertyUpdater(propertyName); if (!propertyUpdater.IsSettable) { LogReadOnlyProperty(propertyName); return; } var targetType = propertyUpdater.TargetType; var glue = GetCachedOrCreateBasic(newValue, targetType); var bridgeUpdater = new BridgeUpdater(_SessionCache); await Context.RunOnUiContextAsync(() => { using (_ListenerRegister.GetPropertySilenter(currentfather.CValue, propertyName)) { var oldValue = propertyUpdater.GetCurrentChildValue(); try { propertyUpdater.Set(glue.CValue); } catch (Exception exception) { LogSetError(propertyName, targetType, glue.CValue, exception); } var actualValue = propertyUpdater.GetCurrentChildValue(); if (Object.Equals(actualValue, glue.CValue)) { var old = currentfather.UpdateGlueProperty(propertyUpdater, glue); bridgeUpdater.Remove(old); bridgeUpdater.CleanAfterChangesOnUiThread(_ListenerRegister.Off); return; } if (!Object.Equals(oldValue, actualValue)) { OnCSharpPropertyChanged(currentfather.CValue, new PropertyChangedEventArgs(propertyName)); } } }); if (!bridgeUpdater.HasUpdatesOnJavascriptContext) { return; } await Context.RunOnJavascriptContextAsync(() => { bridgeUpdater.UpdateOnJavascriptContext(Context.ViewModelUpdater); }); } catch (Exception exception) { LogJavascriptSetException(exception); } }