1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- using FNZCM.BlazorWasm.UI.Components.Bases;
- using Microsoft.JSInterop;
- using Newtonsoft.Json;
- namespace FNZCM.BlazorWasm.UI.Components.FnzBoostrap.Bases
- {
- public class FnzBoostrapComponentBase<T, TOptions> : FnzComponentBase, IAsyncDisposable
- where T : class
- where TOptions : OptionsBase, new()
- {
- protected DotNetObjectReference<FnzBoostrapComponentBase<T, TOptions>> 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();
- }
- }
- }
|