using FNZCM.BlazorWasm.UI.Components.Bases; using Microsoft.JSInterop; using Newtonsoft.Json; namespace FNZCM.BlazorWasm.UI.Components.FnzBoostrap.Bases { public class FnzBoostrapComponentBase : FnzComponentBase, IAsyncDisposable where T : class where TOptions : OptionsBase, new() { protected DotNetObjectReference> dotNetRef { get; } public FnzBoostrapComponentBase() => dotNetRef = DotNetObjectReference.Create(this); public Guid InstanceId { get; } = Guid.NewGuid(); public string ElementId => Prefix + "-" + InstanceId.ToString("n"); protected virtual string Prefix => "fnz.boostrap"; protected TOptions _options = new TOptions(); protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { await JSRuntime.InvokeVoidAsync($"{Prefix}.init", ElementId, JsonConvert.SerializeObject(_options), dotNetRef); _options.ResetChanged(); } else { if (_options.CheckIsChanged()) { await JSRuntime.InvokeVoidAsync($"{Prefix}.sync", ElementId, JsonConvert.SerializeObject(_options), dotNetRef); _options.ResetChanged(); } } } public virtual async ValueTask DisposeAsync() { await JSRuntime.InvokeVoidAsync($"{Prefix}.dispose", ElementId, dotNetRef); dotNetRef.Dispose(); } } }