Skip to content

Commit 22a2a9b

Browse files
authored
priority queue implementation (#573)
* Implement priority queues.
1 parent e3efa50 commit 22a2a9b

File tree

17 files changed

+49
-20
lines changed

17 files changed

+49
-20
lines changed

blazorbootstrap/Components/Alert/Alert.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected override async Task OnInitializedAsync()
4848
objRef ??= DotNetObjectReference.Create(this);
4949
await base.OnInitializedAsync();
5050

51-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.alert.initialize", ElementId, objRef); });
51+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.alert.initialize", ElementId, objRef), new RenderPriority());
5252
}
5353

5454
[JSInvokable]

blazorbootstrap/Components/Button/Button.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected override void OnInitialized()
103103

104104
base.OnInitialized();
105105

106-
if (!string.IsNullOrWhiteSpace(TooltipTitle)) QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.tooltip.initialize", ElementRef); });
106+
if (!string.IsNullOrWhiteSpace(TooltipTitle)) QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.tooltip.initialize", ElementRef), new RenderPriority());
107107
}
108108

109109
protected override async Task OnParametersSetAsync()

blazorbootstrap/Components/Collapse/Collapse.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override async Task OnInitializedAsync()
4646
{
4747
objRef ??= DotNetObjectReference.Create(this);
4848

49-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.collapse.initialize", ElementId, Parent, Toggle, objRef); });
49+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.collapse.initialize", ElementId, Parent, Toggle, objRef), new RenderPriority());
5050

5151
await base.OnInitializedAsync();
5252
}

blazorbootstrap/Components/Core/BlazorBootstrapComponentBase.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public abstract class BlazorBootstrapComponentBase : ComponentBase, IDisposable,
5555
/// <summary>
5656
/// A stack of functions to execute after the rendering.
5757
/// </summary>
58-
private Queue<Func<Task>>? renderQueue;
58+
private PriorityQueue<Func<Task>, RenderPriority>? renderQueue;
5959

6060
#endregion
6161

@@ -248,10 +248,11 @@ protected virtual ValueTask DisposeAsync(bool disposing)
248248
/// Pushes an action to the stack to be executed after the rendering is done.
249249
/// </summary>
250250
/// <param name="action"></param>
251-
protected void QueueAfterRenderAction(Func<Task> action)
251+
/// <param name="renderPriority"></param>
252+
protected void QueueAfterRenderAction(Func<Task> action, RenderPriority renderPriority)
252253
{
253-
renderQueue ??= new Queue<Func<Task>>();
254-
renderQueue.Enqueue(action);
254+
renderQueue ??= new PriorityQueue<Func<Task>, RenderPriority>();
255+
renderQueue.Enqueue(action, renderPriority);
255256
}
256257

257258
#endregion
@@ -385,6 +386,6 @@ public string? StyleNames
385386
return styleNames;
386387
}
387388
}
388-
389+
389390
#endregion
390391
}

blazorbootstrap/Components/Dropdown/Dropdown.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected override void OnInitialized()
4646

4747
base.OnInitialized();
4848

49-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.dropdown.initialize", ElementId, objRef); });
49+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.dropdown.initialize", ElementId, objRef), new RenderPriority());
5050
}
5151

5252
[JSInvokable]

blazorbootstrap/Components/Form/AutoComplete/AutoComplete.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected override async Task OnInitializedAsync()
6666

6767
await base.OnInitializedAsync();
6868

69-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.autocomplete.initialize", ElementRef, objRef); });
69+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.autocomplete.initialize", ElementRef, objRef), new RenderPriority());
7070
}
7171

7272
[JSInvokable]

blazorbootstrap/Components/Modals/Modal.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ protected override async Task OnInitializedAsync()
7272
objRef ??= DotNetObjectReference.Create(this);
7373
await base.OnInitializedAsync();
7474

75-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.modal.initialize", ElementId, UseStaticBackdrop, CloseOnEscape, objRef); });
75+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.modal.initialize", ElementId, UseStaticBackdrop, CloseOnEscape, objRef), new RenderPriority());
7676
}
7777

7878
[JSInvokable]

blazorbootstrap/Components/Offcanvas/Offcanvas.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected override async Task OnInitializedAsync()
5656
objRef ??= DotNetObjectReference.Create(this);
5757
await base.OnInitializedAsync();
5858

59-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.offcanvas.initialize", ElementId, UseStaticBackdrop, CloseOnEscape, IsScrollable, objRef); });
59+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.offcanvas.initialize", ElementId, UseStaticBackdrop, CloseOnEscape, IsScrollable, objRef), new RenderPriority());
6060
}
6161

6262
[JSInvokable]

blazorbootstrap/Components/PdfViewer/PdfViewer.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected override async Task OnInitializedAsync()
2828
objRef ??= DotNetObjectReference.Create(this);
2929
await base.OnInitializedAsync();
3030

31-
QueueAfterRenderAction(async () => await PdfViewerJsInterop.InitializeAsync(objRef!, ElementId!, scale, rotation, Url!));
31+
QueueAfterRenderAction(async () => await PdfViewerJsInterop.InitializeAsync(objRef!, ElementId!, scale, rotation, Url!), new RenderPriority());
3232
}
3333

3434
[JSInvokable]

blazorbootstrap/Components/ScriptLoader/ScriptLoader.razor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected override async Task OnInitializedAsync()
2525
{
2626
objRef ??= DotNetObjectReference.Create(this);
2727

28-
QueueAfterRenderAction(async () => { await JS.InvokeVoidAsync("window.blazorBootstrap.scriptLoader.initialize", ElementId, Async, ScriptId, Source, type, objRef); });
28+
QueueAfterRenderAction(async () => await JS.InvokeVoidAsync("window.blazorBootstrap.scriptLoader.initialize", ElementId, Async, ScriptId, Source, type, objRef), new RenderPriority());
2929

3030
await base.OnInitializedAsync();
3131
}

0 commit comments

Comments
 (0)