Skip to content

Commit f1d1ef5

Browse files
committed
More changes per PR
1 parent fb25d86 commit f1d1ef5

File tree

17 files changed

+1029
-727
lines changed

17 files changed

+1029
-727
lines changed

src/Components/Browser.JS/src/Platform/Circuits/DefaultReconnectDisplay.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,23 @@ export class DefaultReconnectDisplay implements ReconnectDisplay {
88
constructor(private document: Document) {
99
this.modal = this.document.createElement('div');
1010
this.modal.id = AutoReconnectCircuitHandler.DialogId;
11-
this.modal.style.cssText = 'position:fixed;top:0;right:0;bottom:0;left:0;z-index:1000;display:none;overflow:hidden;background-color:#fff;opacity:0.8;text-align:center;font-weight:bold';
11+
12+
const modalStyles = [
13+
"position: fixed",
14+
"top: 0",
15+
"right: 0",
16+
"bottom: 0",
17+
"left: 0",
18+
"z-index: 1000",
19+
"display: none",
20+
"overflow: hidden",
21+
"background-color: #fff",
22+
"opacity: 0.8",
23+
"text-align: center",
24+
"font-weight: bold"
25+
];
26+
27+
this.modal.style.cssText = modalStyles.join(';');
1228
this.modal.innerHTML = '<h5 style="margin-top: 20px"></h5><button style="margin:5px auto 5px">Retry?</button>';
1329
this.message = this.modal.querySelector('h5')!;
1430
this.button = this.modal.querySelector('button')!;
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"extends": "../tsconfig.base.json",
3-
"include": [
4-
"./**/*"
5-
]
2+
"extends": "../tsconfig.base.json"
63
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"extends": "../tsconfig.base.json",
3-
"include": ["./**/*"],
4-
"compilerOptions": {
5-
"noUnusedLocals": false,
6-
"noUnusedParameters": false
7-
}
2+
"extends": "../tsconfig.base.json"
83
}

src/Components/Components/src/Rendering/Renderer.cs

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class Renderer : IDisposable
1919
private readonly ComponentFactory _componentFactory;
2020
private readonly Dictionary<int, ComponentState> _componentStateById = new Dictionary<int, ComponentState>();
2121
private readonly Dictionary<int, EventCallback> _eventBindings = new Dictionary<int, EventCallback>();
22+
private IDispatcher _dispatcher { get; }
2223

2324
private int _nextComponentId = 0; // TODO: change to 'long' when Mono .NET->JS interop supports it
2425
private bool _isBatchInProgress;
@@ -32,15 +33,15 @@ public event UnhandledExceptionEventHandler UnhandledSynchronizationException
3233
{
3334
add
3435
{
35-
if (!(Dispatcher is RendererSynchronizationContext rendererSynchronizationContext))
36+
if (!(_dispatcher is RendererSynchronizationContext rendererSynchronizationContext))
3637
{
3738
return;
3839
}
3940
rendererSynchronizationContext.UnhandledException += value;
4041
}
4142
remove
4243
{
43-
if (!(Dispatcher is RendererSynchronizationContext rendererSynchronizationContext))
44+
if (!(_dispatcher is RendererSynchronizationContext rendererSynchronizationContext))
4445
{
4546
return;
4647
}
@@ -64,25 +65,11 @@ public Renderer(IServiceProvider serviceProvider)
6465
/// <param name="dispatcher">The <see cref="IDispatcher"/> to be for invoking user actions into the <see cref="Renderer"/> context.</param>
6566
public Renderer(IServiceProvider serviceProvider, IDispatcher dispatcher) : this(serviceProvider)
6667
{
67-
Dispatcher = dispatcher;
68+
_dispatcher = dispatcher;
6869
}
6970

70-
/// <summary>
71-
/// Gets the <see cref="IDispatcher"/>
72-
/// </summary>
73-
protected IDispatcher Dispatcher { get; }
74-
7571
internal RenderBatchBuilder RenderBatchBuilder { get; } = new RenderBatchBuilder();
7672

77-
/// <summary>
78-
/// Gets a property that determines if this instance of <see cref="Renderer"/> can render a batch.
79-
///
80-
/// <para>
81-
/// Derivied types can use this property to force queuing up renders for a batch.
82-
/// </para>
83-
/// </summary>
84-
protected virtual bool CanRenderBatch { get; } = true;
85-
8673
/// <summary>
8774
/// Creates an <see cref="IDispatcher"/> that can be used with one or more <see cref="Renderer"/>.
8875
/// </summary>
@@ -103,7 +90,8 @@ protected IComponent InstantiateComponent(Type componentType)
10390
/// </summary>
10491
/// <param name="component">The component.</param>
10592
/// <returns>The component's assigned identifier.</returns>
106-
protected int AssignRootComponentId(IComponent component)
93+
// Internal for unit testing
94+
protected internal int AssignRootComponentId(IComponent component)
10795
=> AttachAndInitComponent(component, -1).ComponentId;
10896

10997
/// <summary>
@@ -262,13 +250,13 @@ public Task DispatchEventAsync(int eventHandlerId, UIEventArgs eventArgs)
262250
public virtual Task Invoke(Action workItem)
263251
{
264252
// This is for example when we run on a system with a single thread, like WebAssembly.
265-
if (Dispatcher == null)
253+
if (_dispatcher == null)
266254
{
267255
workItem();
268256
return Task.CompletedTask;
269257
}
270258

271-
if (SynchronizationContext.Current == Dispatcher)
259+
if (SynchronizationContext.Current == _dispatcher)
272260
{
273261
// This is an optimization for when the dispatcher is also a syncronization context, like in the default case.
274262
// No need to dispatch. Avoid deadlock by invoking directly.
@@ -277,7 +265,7 @@ public virtual Task Invoke(Action workItem)
277265
}
278266
else
279267
{
280-
return Dispatcher.Invoke(workItem);
268+
return _dispatcher.Invoke(workItem);
281269
}
282270
}
283271

@@ -289,20 +277,20 @@ public virtual Task Invoke(Action workItem)
289277
public virtual Task InvokeAsync(Func<Task> workItem)
290278
{
291279
// This is for example when we run on a system with a single thread, like WebAssembly.
292-
if (Dispatcher == null)
280+
if (_dispatcher == null)
293281
{
294282
return workItem();
295283
}
296284

297-
if (SynchronizationContext.Current == Dispatcher)
285+
if (SynchronizationContext.Current == _dispatcher)
298286
{
299287
// This is an optimization for when the dispatcher is also a syncronization context, like in the default case.
300288
// No need to dispatch. Avoid deadlock by invoking directly.
301289
return workItem();
302290
}
303291
else
304292
{
305-
return Dispatcher.InvokeAsync(workItem);
293+
return _dispatcher.InvokeAsync(workItem);
306294
}
307295
}
308296

@@ -417,7 +405,7 @@ private void EnsureSynchronizationContext()
417405
// Plus, any other logic that mutates state accessed during rendering also
418406
// needs not to run concurrently with rendering so should be dispatched to
419407
// the renderer's sync context.
420-
if (Dispatcher is SynchronizationContext synchronizationContext && SynchronizationContext.Current != synchronizationContext)
408+
if (_dispatcher is SynchronizationContext synchronizationContext && SynchronizationContext.Current != synchronizationContext)
421409
{
422410
throw new InvalidOperationException(
423411
"The current thread is not associated with the renderer's synchronization context. " +
@@ -436,22 +424,14 @@ private ComponentState GetOptionalComponentState(int componentId)
436424
? componentState
437425
: null;
438426

439-
/// <summary>
440-
/// Processes the render queue.
441-
/// </summary>
442-
protected void ProcessRenderQueue()
427+
private void ProcessRenderQueue()
443428
{
444-
if (!CanRenderBatch)
445-
{
446-
return;
447-
}
448-
449429
var updateDisplayTask = Task.CompletedTask;
450430
_isBatchInProgress = true;
451431
try
452432
{
453433
// Process render queue until empty
454-
while (CanRenderBatch && RenderBatchBuilder.ComponentRenderQueue.Count > 0)
434+
while (RenderBatchBuilder.ComponentRenderQueue.Count > 0)
455435
{
456436
var nextToRender = RenderBatchBuilder.ComponentRenderQueue.Dequeue();
457437
RenderInExistingBatch(nextToRender);

src/Components/Components/test/RendererTest.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,27 +3103,6 @@ public void DisposingRenderer_CapturesExceptionsFromAllRegisteredComponents()
31033103
Assert.Contains(exception2, renderer.HandledExceptions);
31043104
}
31053105

3106-
[Fact]
3107-
public void RendersAreBuffered_WhenCanRenderBatchIsReset()
3108-
{
3109-
// Arrange
3110-
var renderer = new TestRenderer();
3111-
renderer.SetCanRenderBatch(false);
3112-
var component = new TestComponent(builder =>
3113-
{
3114-
builder.AddContent(0, "Hello");
3115-
builder.OpenComponent<DisposableComponent>(1);
3116-
builder.CloseComponent();
3117-
});
3118-
3119-
var componentId = renderer.AssignRootComponentId(component);
3120-
component.TriggerRender();
3121-
3122-
Assert.Empty(renderer.Batches);
3123-
var entry = Assert.Single(renderer.RenderBatchBuilder.ComponentRenderQueue);
3124-
Assert.Equal(componentId, entry.ComponentState.ComponentId);
3125-
}
3126-
31273106
private class NoOpRenderer : Renderer
31283107
{
31293108
public NoOpRenderer() : base(new TestServiceProvider(), new RendererSynchronizationContext())

0 commit comments

Comments
 (0)