perf(adminui): cache the modals' DynamicComponent parameter dictionaries (R04 H2)
DriverConfigModal, DeviceModal and RawTagModal built a new parameter dictionary and new EventCallbacks every render. ParameterDictionaryCache reuses the dictionary while the values it carries are unchanged and rebuilds it with the current value when one changes (a build-once cache would strand edits); the callbacks are created once. Blazor still re-sets an EventCallback-bearing child's parameters per parent render, so the forms' _lastParsed guards stay. Refs #745 Claude-Session: https://claude.ai/code/session_01Ub9hGmYLQvn9XETzw7CMsT
This commit is contained in:
@@ -217,15 +217,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Parameters handed to the typed TagConfig editor. Internal so tests can assert them.</summary>
|
||||
internal IDictionary<string, object> BuildEditorParameters() => new Dictionary<string, object>
|
||||
{
|
||||
["ConfigJson"] = _form.TagConfig,
|
||||
["ConfigJsonChanged"] = EventCallback.Factory.Create<string>(this, v => _form.TagConfig = v),
|
||||
["DriverType"] = DriverType ?? "",
|
||||
// Live accessor, not a snapshot: the picker reads it when the operator clicks Browse.
|
||||
["GetDriverConfigJson"] = (Func<string>)(() => _mergedConfigJson ?? "{}"),
|
||||
};
|
||||
/// <summary>Parameters handed to the typed TagConfig editor. Internal so tests can assert them. Cached
|
||||
/// on the values it carries and rebuilt when one changes (never build-once, which would pin the first
|
||||
/// render's TagConfig); the callback and accessor are created once (R04 H2).</summary>
|
||||
internal IDictionary<string, object> BuildEditorParameters() => _editorParameterCache.Get(
|
||||
[_form.TagConfig, DriverType ?? ""],
|
||||
() => new Dictionary<string, object>
|
||||
{
|
||||
["ConfigJson"] = _form.TagConfig,
|
||||
["ConfigJsonChanged"] = _configJsonChanged ??=
|
||||
EventCallback.Factory.Create<string>(this, v => _form.TagConfig = v),
|
||||
["DriverType"] = DriverType ?? "",
|
||||
// Live accessor, not a snapshot: the picker reads it when the operator clicks Browse.
|
||||
["GetDriverConfigJson"] = _getDriverConfigJson ??= () => _mergedConfigJson ?? "{}",
|
||||
});
|
||||
private readonly ParameterDictionaryCache _editorParameterCache = new();
|
||||
private EventCallback<string>? _configJsonChanged;
|
||||
private Func<string>? _getDriverConfigJson;
|
||||
|
||||
private async Task SaveAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user