private static void InterpretEventDescriptor(BrowserEventDescriptor eventDescriptor)
        {
            // The incoming field value can be either a bool or a string, but since the .NET property
            // type is 'object', it will deserialize initially as a JsonElement
            var fieldInfo = eventDescriptor.EventFieldInfo;

            if (fieldInfo != null)
            {
                if (fieldInfo.FieldValue is JsonElement attributeValueJsonElement)
                {
                    switch (attributeValueJsonElement.ValueKind)
                    {
                    case JsonValueKind.True:
                    case JsonValueKind.False:
                        fieldInfo.FieldValue = attributeValueJsonElement.GetBoolean();
                        break;

                    default:
                        fieldInfo.FieldValue = attributeValueJsonElement.GetString();
                        break;
                    }
                }
                else
                {
                    // Unanticipated value type. Ensure we don't do anything with it.
                    eventDescriptor.EventFieldInfo = null;
                }
            }
        }
Beispiel #2
0
        public static Task DispatchEvent(
            BrowserEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var eventArgs = ParseEventArgsJson(eventDescriptor.EventArgsType, eventArgsJson);
            var renderer  = RendererRegistry.Current.Find(eventDescriptor.BrowserRendererId);

            return(renderer.DispatchEventAsync(eventDescriptor.EventHandlerId, eventArgs));
        }
Beispiel #3
0
        public static void DispatchEvent(
            BrowserEventDescriptor eventDescriptor, string eventArgsJson)
        {
            var eventArgs       = ParseEventArgsJson(eventDescriptor.EventArgsType, eventArgsJson);
            var browserRenderer = BrowserRendererRegistry.Find(eventDescriptor.BrowserRendererId);

            browserRenderer.DispatchBrowserEvent(
                eventDescriptor.ComponentId,
                eventDescriptor.EventHandlerId,
                eventArgs);
        }
        public static Task DispatchEvent(
            BrowserEventDescriptor eventDescriptor, string eventArgsJson)
        {
            // Be sure we only run one event handler at once. Although they couldn't run
            // simultaneously anyway (there's only one thread), they could run nested on
            // the stack if somehow one event handler triggers another event synchronously.
            // We need event handlers not to overlap because (a) that's consistent with
            // server-side Blazor which uses a sync context, and (b) the rendering logic
            // relies completely on the idea that within a given scope it's only building
            // or processing one batch at a time.
            //
            // The only currently known case where this makes a difference is in the E2E
            // tests in ReorderingFocusComponent, where we hit what seems like a Chrome bug
            // where mutating the DOM cause an element's "change" to fire while its "input"
            // handler is still running (i.e., nested on the stack) -- this doesn't happen
            // in Firefox. Possibly a future version of Chrome may fix this, but even then,
            // it's conceivable that DOM mutation events could trigger this too.

            if (isDispatchingEvent)
            {
                var info = new IncomingEventInfo(eventDescriptor, eventArgsJson);
                deferredIncomingEvents.Enqueue(info);
                return(info.TaskCompletionSource.Task);
            }
            else
            {
                isDispatchingEvent = true;
                try
                {
                    var eventArgs = ParseEventArgsJson(eventDescriptor.EventArgsType, eventArgsJson);
                    var renderer  = RendererRegistry.Current.Find(eventDescriptor.BrowserRendererId);
                    return(renderer.DispatchEventAsync(eventDescriptor.EventHandlerId, eventArgs));
                }
                finally
                {
                    isDispatchingEvent = false;
                    if (deferredIncomingEvents.Count > 0)
                    {
                        ProcessNextDeferredEvent();
                    }
                }
            }
        }
 public IncomingEventInfo(BrowserEventDescriptor eventDescriptor, string eventArgsJson)
 {
     EventDescriptor      = eventDescriptor;
     EventArgsJson        = eventArgsJson;
     TaskCompletionSource = new TaskCompletionSource <object>();
 }