Skip to content

Instantly share code, notes, and snippets.

View gskachkov's full-sized avatar

Oleksander Skachkov gskachkov

  • Itera Consulting
  • Ukraine, Kiev
View GitHub Profile
function utf8ToString(h, p) {
let s = "";
for (i = p; h[i]; i++) {
s += String.fromCharCode(h[i]);
}
return s;
}
let m = new WebAssembly.Instance(new WebAssembly.Module(buffer));
let h = new Uint8Array(m.exports.memory.buffer);
function getString () {
return "Hello world";
}
const value = getString();
console.log(value);
namespace BlazorExport
{
using System;
public static class Helper
{
public static string Log(string msg) {
Console.WriteLine(msg);
return "success";
}
Blazor.registerFunction('invoke', msg => {
const logMethod = Blazor.platform.findMethod(
'StandaloneApp', // Assembly name
'BlazorExport', // Namespace
'Helper', // Class name
'Log' // Method name
);
const wasmResult = Blazor.platform.callMethod(logMethod, null, [
Blazor.platform.toDotNetString('Invoke from JS')
const log = Blazor.platform.findMethod(
'BlazorExport', // Assembly name
'BlazorExport', // Namespace
'Helpers', // Class name
'Log' // Method name
);
log('Invoke from JS');
namespace BlazorExport
{
public static class Helpers
{
public static void Log(string msg)
{
Console.WriteLine(msg);
}
}
}
public static void TriggerJsConsoleLog()
{
RegisteredFunction.Invoke<bool>(
"JavaScriptConsoleLog",
"Invoked from Blazor");
}
Blazor.registerFunction('JavaScriptConsoleLog', message => {
console.log(message);
return true;
});
[Layout(typeof(MainLayout)), Route("/fetchdata"), Route("/fetchdata/{StartDate:datetime}")]
public class FetchData : BlazorComponent
{
// Fields
[DebuggerBrowsable(0), CompilerGenerated]
private DateTime <StartDate>k__BackingField;
private WeatherForecast[] forecasts;
[DebuggerBrowsable(0), CompilerGenerated]
private HttpClient <Http>k__BackingField;
[Route("/counter"), Layout(typeof(MainLayout))]
public class Counter : BlazorComponent
{
private int currCount = 0;
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Counter");