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
const cachedFunctions = {} | |
function batchJsInterop(calls) { | |
return calls.map(call => { | |
try { | |
// Find function if needed | |
if (!(call.identifier in cachedFunctions)) { | |
var result = window; | |
var lastSegment = null; |
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
using System; | |
using System.Collections.Concurrent; | |
using System.Linq.Expressions; | |
using System.Threading.Tasks; | |
namespace Blazor.Diagrams.Interop | |
{ | |
public static class TcsUtil | |
{ | |
private static readonly Type _tcsType = typeof(TaskCompletionSource<>); |
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
using Microsoft.JSInterop; | |
using System; | |
using System.Buffers; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.Text.Json; | |
using System.Threading; | |
using System.Threading.Tasks; |
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 class JsCall | |
{ | |
public JsCall(long id, string identifier, object[] args, object tcs, Type type) | |
{ | |
Id = id; | |
Identifier = identifier; | |
Args = args; | |
Tcs = tcs; | |
Type = type; | |
} |
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
Action simpleAction = () => Console.WriteLine("Simple Action"); | |
Action<int> actionWithArg = (i) => Console.WriteLine("Simple Action " + i); | |
Func<Task> taskFunc = () => Task.CompletedTask; | |
Func<int, Task> taskWithArgFunc = (i) => Task.FromResult(i); | |
MulticastDelegate delegate1 = simpleAction; | |
MulticastDelegate delegate2 = actionWithArg; | |
MulticastDelegate delegate3 = taskFunc; | |
MulticastDelegate delegate4 = taskWithArgFunc; |
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
Task IHandleEvent.HandleEventAsync(EventCallbackWorkItem callback, object? arg) | |
{ | |
var task = callback.InvokeAsync(arg); | |
var shouldAwaitTask = task.Status != TaskStatus.RanToCompletion && | |
task.Status != TaskStatus.Canceled; | |
// After each event, we synchronously re-render (unless !ShouldRender()) | |
// This just saves the developer the trouble of putting "StateHasChanged();" | |
// at the end of every event callback. | |
StateHasChanged(); |
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
// Copyright (c) .NET Foundation. All rights reserved. | |
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | |
using System; | |
using System.Reflection; | |
using System.Threading.Tasks; | |
namespace Microsoft.AspNetCore.Components | |
{ | |
/// <summary> |
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
public readonly struct EventCallback : IEventCallback | |
{ | |
internal readonly MulticastDelegate Delegate; | |
internal readonly IHandleEvent Receiver; | |
public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate) | |
{ | |
Receiver = receiver; | |
Delegate = @delegate; | |
} |
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
public EventCallback Create(object receiver, Func<Task> callback); | |
public EventCallback Create(object receiver, Func<object, Task> callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, EventCallback callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, EventCallback<TValue> callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, Action callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, Action<TValue> callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, Func<Task> callback); | |
public EventCallback<TValue> Create<TValue>(object receiver, Func<TValue, Task> callback); |
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
protected override void BuildRenderTree(RenderTreeBuilder builder) | |
{ | |
// Other stuff | |
builder.AddAttribute(5, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, SomeMethod)); | |
// Other stuff | |
} |
NewerOlder