diff --git a/packages/Ignis.Components.Reactivity/ReactiveValue.cs b/packages/Ignis.Components.Reactivity/ReactiveValue.cs index 3964ca07..56ace422 100644 --- a/packages/Ignis.Components.Reactivity/ReactiveValue.cs +++ b/packages/Ignis.Components.Reactivity/ReactiveValue.cs @@ -1,10 +1,13 @@ -namespace Ignis.Components.Reactivity; +using Ignis.Components.Extensions; + +namespace Ignis.Components.Reactivity; public sealed class ReactiveValue where T : struct { private readonly IList> _sections = new List>(); private readonly IgnisComponentBase _owner; + private IgnisReactivityExtension? _extension; private T _value; public ReactiveValue(IgnisComponentBase owner, T value) @@ -17,6 +20,8 @@ public T Value { get { + Initialize(); + return _value; } set @@ -34,6 +39,18 @@ public T Value } } + private void Initialize() + { + if (_extension != null) return; + + _extension = _owner.GetExtension(); + if (_extension == null) + { + throw new InvalidOperationException( + "To use the Ignis reactivity system please make sure to call AddIgnisReactivity() in your Program.cs."); + } + } + public void SetSilently(T value) { _value = value; diff --git a/tests/Ignis.Tests.Components.Reactivity/ReactiveSectionTests.razor b/tests/Ignis.Tests.Components.Reactivity/ReactiveSectionTests.razor index 76ab090f..05e6d49d 100644 --- a/tests/Ignis.Tests.Components.Reactivity/ReactiveSectionTests.razor +++ b/tests/Ignis.Tests.Components.Reactivity/ReactiveSectionTests.razor @@ -6,6 +6,7 @@ public void Test() { Services.AddIgnisTestServices(); + Services.AddIgnisReactivity(); var cut = RenderComponent(); diff --git a/tests/Ignis.Tests.Components.Reactivity/ReactiveValueTests.razor b/tests/Ignis.Tests.Components.Reactivity/ReactiveValueTests.razor index 477463f0..1abbd631 100644 --- a/tests/Ignis.Tests.Components.Reactivity/ReactiveValueTests.razor +++ b/tests/Ignis.Tests.Components.Reactivity/ReactiveValueTests.razor @@ -2,10 +2,20 @@ @code { + [Fact] + public void MissingCallToAddIgnisReactivity() + { + Services.AddIgnisTestServices(); + + var exception = Assert.Throws(() => RenderComponent()); + Assert.Equal("To use the Ignis reactivity system please make sure to call AddIgnisReactivity() in your Program.cs.", exception.Message); + } + [Fact] public void SilentCounter() { Services.AddIgnisTestServices(); + Services.AddIgnisReactivity(); var cut = RenderComponent(); Assert.Equal(1, cut.RenderCount); @@ -25,6 +35,7 @@ public void ReactiveCounter() { Services.AddIgnisTestServices(); + Services.AddIgnisReactivity(); var cut = RenderComponent(); Assert.Equal(1, cut.RenderCount); diff --git a/tests/e2e/Ignis.Tests.E2E.Website/Program.cs b/tests/e2e/Ignis.Tests.E2E.Website/Program.cs index 9bacac63..630f7380 100644 --- a/tests/e2e/Ignis.Tests.E2E.Website/Program.cs +++ b/tests/e2e/Ignis.Tests.E2E.Website/Program.cs @@ -1,4 +1,5 @@ using Ignis.Components; +using Ignis.Components.Reactivity; using Ignis.Components.WebAssembly; using Ignis.Tests.E2E.Website; using Microsoft.AspNetCore.Components.Web; diff --git a/tests/e2e/Ignis.Tests.E2E.Website/Shared/WrappedCustomDialogWithForm.razor b/tests/e2e/Ignis.Tests.E2E.Website/Shared/WrappedCustomDialogWithForm.razor index f0ee4699..35727d01 100644 --- a/tests/e2e/Ignis.Tests.E2E.Website/Shared/WrappedCustomDialogWithForm.razor +++ b/tests/e2e/Ignis.Tests.E2E.Website/Shared/WrappedCustomDialogWithForm.razor @@ -28,6 +28,13 @@

+ + @if (_model.SelectedType != null) + { +

+ @_model.SelectedType.Name +

+ }