-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow outlet of dialogs within a transition (#6)
* allow outlet of dialogs with a transition * tests * abstract OutletBase * implement IOutletComponent identifier concept * TODO
- Loading branch information
1 parent
af6757c
commit 589fe64
Showing
8 changed files
with
184 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Ignis.Components; | ||
|
||
public abstract class OutletBase : IgnisComponentBase, IOutlet, IOutletRegistrySubscriber, IDisposable | ||
{ | ||
private readonly IList<IOutletComponent> _components = new List<IOutletComponent>(); | ||
|
||
private IOutletRegistry? _outletRegistry; | ||
|
||
protected IEnumerable<IOutletComponent> Components => _components; | ||
|
||
[Inject] | ||
public IOutletRegistry? OutletRegistry | ||
{ | ||
get => _outletRegistry; | ||
set | ||
{ | ||
_outletRegistry?.Unsubscribe(this); | ||
|
||
_outletRegistry = value; | ||
_outletRegistry?.Subscribe(this); | ||
} | ||
} | ||
|
||
/// <inheritdoc /> | ||
public virtual void OnComponentRegistered(IOutletComponent component) | ||
{ | ||
if (_components.Contains(component) || _components.Any(c => c.Identifier.Equals(component.Identifier))) return; | ||
|
||
_components.Add(component); | ||
|
||
component.SetOutlet(this); | ||
|
||
base.Update(); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public void OnComponentUnregistered(IOutletComponent component) | ||
{ | ||
if (!_components.Contains(component)) return; | ||
|
||
_components.Remove(component); | ||
|
||
component.SetFree(); | ||
|
||
base.Update(); | ||
} | ||
|
||
void IOutlet.Update(bool async) | ||
{ | ||
base.Update(async); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (!disposing) return; | ||
|
||
_outletRegistry?.Unsubscribe(this); | ||
_outletRegistry = null; | ||
|
||
foreach (var component in _components) | ||
{ | ||
component.SetFree(); | ||
} | ||
|
||
_components.Clear(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
~OutletBase() | ||
{ | ||
Dispose(false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
@inherits TestContext | ||
|
||
@code | ||
{ | ||
[Fact] | ||
public void Outlet() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
const string dialogId = "dialog"; | ||
const string outletId = "dialog-outlet"; | ||
|
||
var cut = Render(@<div> | ||
<DialogOutlet AsElement="div" id="@outletId"/> | ||
<Dialog IsOpen id="@dialogId"></Dialog> | ||
</div>); | ||
|
||
var dialogDiv = cut.Find($"#{dialogId}"); | ||
var outletDiv = cut.Find($"#{outletId}"); | ||
Assert.True(outletDiv.Contains(dialogDiv)); | ||
} | ||
|
||
[Fact] | ||
public void IgnoreOutlet() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
const string dialogId = "dialog"; | ||
const string outletId = "dialog-outlet"; | ||
|
||
var cut = Render(@<div> | ||
<DialogOutlet AsElement="div" id="@outletId"/> | ||
<Dialog IgnoreOutlet IsOpen id="@dialogId"></Dialog> | ||
</div>); | ||
|
||
var dialogDiv = cut.Find($"#{dialogId}"); | ||
var outletDiv = cut.Find($"#{outletId}"); | ||
Assert.False(outletDiv.Contains(dialogDiv)); | ||
} | ||
|
||
[Fact] | ||
public void OutletWithTransition() | ||
{ | ||
Services.AddIgnis(); | ||
Services.AddSingleton<IHostContext, TestHostContext>(); | ||
|
||
JSInterop.Mode = JSRuntimeMode.Loose; | ||
|
||
const string dialogId = "dialog"; | ||
const string outletId = "dialog-outlet"; | ||
const string transitionId = "dialog-transition"; | ||
|
||
var cut = Render(@<div> | ||
<DialogOutlet AsElement="div" id="@outletId"/> | ||
<Transition Show id="@transitionId"> | ||
<Dialog IsOpen id="@dialogId"></Dialog> | ||
</Transition> | ||
</div>); | ||
|
||
var transitionDiv = cut.Find($"#{transitionId}"); | ||
var dialogDiv = cut.Find($"#{dialogId}"); | ||
var outletDiv = cut.Find($"#{outletId}"); | ||
Assert.True(outletDiv.Contains(transitionDiv)); | ||
Assert.True(transitionDiv.Contains(dialogDiv)); | ||
} | ||
} |