Skip to content

Instantly share code, notes, and snippets.

View zHaytam's full-sized avatar
🎯
Focusing

Haytam Zanid zHaytam

🎯
Focusing
View GitHub Profile
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;
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<>);
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;
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;
}
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;
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();
// 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>
public readonly struct EventCallback : IEventCallback
{
internal readonly MulticastDelegate Delegate;
internal readonly IHandleEvent Receiver;
public EventCallback(IHandleEvent receiver, MulticastDelegate @delegate)
{
Receiver = receiver;
Delegate = @delegate;
}
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);
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
// Other stuff
builder.AddAttribute(5, "onclick", EventCallback.Factory.Create<MouseEventArgs>(this, SomeMethod));
// Other stuff
}