Skip to content

Commit e8849ae

Browse files
committed
2.4.0.7
1 parent 724b722 commit e8849ae

7 files changed

Lines changed: 87 additions & 22 deletions
-95.9 KB
Binary file not shown.
96.2 KB
Binary file not shown.

Blazor.WebForm.Components/Base/ControlComponentBase.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public abstract class ControlComponentBase<TControl> : ControlComponent<TControl
1919
private IReadOnlyDictionary<string, object> _attributes;
2020
private EventHandlerDictionary _events;
2121
private bool _firstSet = true;
22+
private bool _inSetParams;
2223

2324
private bool _callbacking = false;
2425

@@ -223,7 +224,7 @@ EventHandlerDictionary IParameterViewComponent.Events
223224
{
224225
if (_events == null)
225226
{
226-
_events = new EventHandlerDictionary();
227+
_events = new EventHandlerDictionary(() => _inSetParams);
227228
}
228229
return _events;
229230
}
@@ -335,7 +336,15 @@ public override Task SetParametersAsync(ParameterView parameters)
335336
{
336337
_parameters = this.FilterParameters(ref parameters);
337338
}
338-
return base.SetParametersAsync(parameters);
339+
try
340+
{
341+
_inSetParams = true;
342+
return base.SetParametersAsync(parameters);
343+
}
344+
finally
345+
{
346+
_inSetParams = false;
347+
}
339348
}
340349

341350
protected override void OnAfterRender(bool firstRender)

Blazor.WebForm.Components/Base/EventHandlerDictionary.cs

Lines changed: 63 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ internal class EventHandlerDictionary
1212
{
1313
private abstract class EventProperty
1414
{
15+
private readonly Func<bool> _inSetParams;
16+
1517
public abstract object Handler { get; set; }
1618

1719
public abstract object BindHandler { get; set; }
@@ -20,6 +22,19 @@ private abstract class EventProperty
2022

2123
public abstract bool IsBoth { get; }
2224

25+
protected bool InSetParams
26+
{
27+
get
28+
{
29+
return _inSetParams != null && _inSetParams.Invoke();
30+
}
31+
}
32+
33+
public EventProperty(Func<bool> inSetParams)
34+
{
35+
_inSetParams = inSetParams;
36+
}
37+
2338
public abstract void Add();
2439

2540
public abstract void Remove();
@@ -31,6 +46,7 @@ private class GeneralEventProperty : EventProperty
3146
private readonly Action<EventHandler> _remove;
3247
private EventHandler _handler;
3348
private EventHandler _bindHandler;
49+
private bool _invoking;
3450

3551
public override object Handler
3652
{
@@ -72,7 +88,8 @@ public override bool IsBoth
7288
}
7389
}
7490

75-
public GeneralEventProperty(Action<EventHandler> add, Action<EventHandler> remove)
91+
public GeneralEventProperty(Func<bool> inSetParams, Action<EventHandler> add, Action<EventHandler> remove)
92+
: base(inSetParams)
7693
{
7794
_add = add;
7895
_remove = remove;
@@ -90,13 +107,24 @@ public override void Remove()
90107

91108
private void Invoke(object sender, EventArgs e)
92109
{
93-
if (_bindHandler != null)
94-
{
95-
_bindHandler.Invoke(sender, e);
96-
}
97-
else
110+
if (!_invoking)
98111
{
99-
_handler?.Invoke(sender, e);
112+
try
113+
{
114+
_invoking = true;
115+
if (!this.InSetParams && _bindHandler != null)
116+
{
117+
_bindHandler.Invoke(sender, e);
118+
}
119+
else
120+
{
121+
_handler?.Invoke(sender, e);
122+
}
123+
}
124+
finally
125+
{
126+
_invoking = false;
127+
}
100128
}
101129
}
102130
}
@@ -107,6 +135,7 @@ private class EventProperty<TEventArgs> : EventProperty
107135
private readonly Action<EventHandler<TEventArgs>> _remove;
108136
private EventHandler<TEventArgs> _handler;
109137
private EventHandler<TEventArgs> _bindHandler;
138+
private bool _invoking;
110139

111140
public override object Handler
112141
{
@@ -148,7 +177,8 @@ public override bool IsBoth
148177
}
149178
}
150179

151-
public EventProperty(Action<EventHandler<TEventArgs>> add, Action<EventHandler<TEventArgs>> remove)
180+
public EventProperty(Func<bool> inSetParams, Action<EventHandler<TEventArgs>> add, Action<EventHandler<TEventArgs>> remove)
181+
: base(inSetParams)
152182
{
153183
_add = add;
154184
_remove = remove;
@@ -166,18 +196,35 @@ public override void Remove()
166196

167197
private void Invoke(object sender, TEventArgs e)
168198
{
169-
if (_bindHandler != null)
170-
{
171-
_bindHandler.Invoke(sender, e);
172-
}
173-
else
199+
if (!_invoking)
174200
{
175-
_handler?.Invoke(sender, e);
201+
try
202+
{
203+
_invoking = true;
204+
if (!this.InSetParams && _bindHandler != null)
205+
{
206+
_bindHandler.Invoke(sender, e);
207+
}
208+
else
209+
{
210+
_handler?.Invoke(sender, e);
211+
}
212+
}
213+
finally
214+
{
215+
_invoking = false;
216+
}
176217
}
177218
}
178219
}
179220

180221
private readonly ConcurrentDictionary<string, EventProperty> _events = new ConcurrentDictionary<string, EventProperty>();
222+
private readonly Func<bool> _inSetParams;
223+
224+
public EventHandlerDictionary(Func<bool> inSetParams)
225+
{
226+
_inSetParams = inSetParams;
227+
}
181228

182229
public void RemoveAll()
183230
{
@@ -267,14 +314,14 @@ private void SetBindEventProperty<TArg>(string propertyName, object bindHandler,
267314

268315
private EventProperty CreateEventProperty(string propertyName, (Action<EventHandler> add, Action<EventHandler> remove) args)
269316
{
270-
EventProperty eventProperty = new GeneralEventProperty(args.add, args.remove);
317+
EventProperty eventProperty = new GeneralEventProperty(_inSetParams, args.add, args.remove);
271318
eventProperty.Add();
272319
return eventProperty;
273320
}
274321

275322
private EventProperty CreateEventProperty<TEventArgs>(string propertyName, (Action<EventHandler<TEventArgs>> add, Action<EventHandler<TEventArgs>> remove) args)
276323
{
277-
EventProperty eventProperty = new EventProperty<TEventArgs>(args.add, args.remove);
324+
EventProperty eventProperty = new EventProperty<TEventArgs>(_inSetParams, args.add, args.remove);
278325
eventProperty.Add();
279326
return eventProperty;
280327
}

Blazor.WebForm.Components/Blazor.WebForm.Components.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<SignAssembly>true</SignAssembly>
66
<AssemblyOriginatorKeyFile>Blazor.WebForm.Components.pfx</AssemblyOriginatorKeyFile>
7-
<Version>2.4.0.6</Version>
7+
<Version>2.4.0.7</Version>
88
<RootNamespace>asp</RootNamespace>
99
<Copyright>Jurio li</Copyright>
1010
<AssemblyName>Blazor.WebForm.Components</AssemblyName>
@@ -17,7 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Applied" Version="1.2.1.8" />
20-
<PackageReference Include="Blazor.WebForm.UI" Version="2.4.0.6" />
20+
<PackageReference Include="Blazor.WebForm.UI" Version="2.4.0.7" />
2121
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.3" />
2222
</ItemGroup>
2323

Blazor.WebForm.Components/Inner/Base/ControlPropertyComponent.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,15 @@ public override Task SetParametersAsync(ParameterView parameters)
217217
{
218218
this.FilterParameters(ref parameters);
219219
}
220-
return base.SetParametersAsync(parameters);
220+
try
221+
{
222+
_inSetParams = true;
223+
return base.SetParametersAsync(parameters);
224+
}
225+
finally
226+
{
227+
_inSetParams = false;
228+
}
221229
}
222230

223231
//public void DataBind()

Blazor.WebForm.Components/Inner/Base/PropertyComponent.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class PropertyComponent<T> : IParameterViewComponent
1616
private RenderFragment _renderFragment;
1717

1818
private EventHandlerDictionary _events;
19+
internal bool _inSetParams;
1920

2021
[CascadingParameter]
2122
protected internal T Owner { get; set; }
@@ -36,7 +37,7 @@ EventHandlerDictionary IParameterViewComponent.Events
3637
{
3738
if (_events == null)
3839
{
39-
_events = new EventHandlerDictionary();
40+
_events = new EventHandlerDictionary(() => _inSetParams);
4041
}
4142
return _events;
4243
}

0 commit comments

Comments
 (0)