Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/Ramstack.HtmxToolkit/HtmxResponseHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,33 @@ public IReadOnlyDictionary<string, object> Trigger
}

/// <summary>
/// Gets or sets the <c>HX-Trigger-After-Settle</c> header, which specifies a dictionary of client-side events
/// to trigger after the htmx request has settled.
/// Gets or sets the <c>HX-Trigger-After-Swap</c> header, which specifies a dictionary of client-side events
/// to trigger after the response content has been swapped into the DOM.
/// </summary>
/// <remarks>
/// Event values are accumulated for the current response and serialized into the header immediately
/// before the response starts.
/// </remarks>
[MaybeNull]
public IReadOnlyDictionary<string, object> TriggerAfterSettle
public IReadOnlyDictionary<string, object> TriggerAfterSwap
{
get => PendingEvents.TryGet(_response)?.GetEvents(HtmxTriggerTiming.AfterSettle);
set => PendingEvents.GetOrCreate(_response).SetEvents(HtmxTriggerTiming.AfterSettle, value);
get => PendingEvents.TryGet(_response)?.GetEvents(HtmxTriggerTiming.AfterSwap);
set => PendingEvents.GetOrCreate(_response).SetEvents(HtmxTriggerTiming.AfterSwap, value);
}

/// <summary>
/// Gets or sets the <c>HX-Trigger-After-Swap</c> header, which specifies a dictionary of client-side events
/// to trigger after the response content has been swapped into the DOM.
/// Gets or sets the <c>HX-Trigger-After-Settle</c> header, which specifies a dictionary of client-side events
/// to trigger after the htmx request has settled.
/// </summary>
/// <remarks>
/// Event values are accumulated for the current response and serialized into the header immediately
/// before the response starts.
/// </remarks>
[MaybeNull]
public IReadOnlyDictionary<string, object> TriggerAfterSwap
public IReadOnlyDictionary<string, object> TriggerAfterSettle
{
get => PendingEvents.TryGet(_response)?.GetEvents(HtmxTriggerTiming.AfterSwap);
set => PendingEvents.GetOrCreate(_response).SetEvents(HtmxTriggerTiming.AfterSwap, value);
get => PendingEvents.TryGet(_response)?.GetEvents(HtmxTriggerTiming.AfterSettle);
set => PendingEvents.GetOrCreate(_response).SetEvents(HtmxTriggerTiming.AfterSettle, value);
}

private static string? GetHeader(IHeaderDictionary headers, string key)
Expand Down
12 changes: 6 additions & 6 deletions src/Ramstack.HtmxToolkit/HtmxTriggerTiming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ public enum HtmxTriggerTiming
Receive,

/// <summary>
/// Maps to the <c>HX-Trigger-After-Settle</c> header that is used to trigger an event
/// on the client side after the htmx request has settled.
/// Maps to the <c>HX-Trigger-After-Swap</c> header that is used to trigger an event
/// on the client side after the htmx request has been swapped.
/// </summary>
AfterSettle,
AfterSwap,

/// <summary>
/// Maps to the <c>HX-Trigger-After-Swap</c> header that is used to trigger an event
/// on the client side after the htmx request has been swapped.
/// Maps to the <c>HX-Trigger-After-Settle</c> header that is used to trigger an event
/// on the client side after the htmx request has settled.
/// </summary>
AfterSwap
AfterSettle
}
18 changes: 9 additions & 9 deletions src/Ramstack.HtmxToolkit/PendingEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace Ramstack.HtmxToolkit;
internal sealed class PendingEvents(HttpResponse response)
{
private Dictionary<string, object>? _receive;
private Dictionary<string, object>? _afterSettle;
private Dictionary<string, object>? _afterSwap;
private Dictionary<string, object>? _afterSettle;

/// <summary>
/// Adds the specified events to the pending set for the given <paramref name="timing"/>.
Expand All @@ -27,8 +27,8 @@ public void AddEvents(HtmxTriggerTiming timing, IReadOnlyDictionary<string, obje
var current = timing switch
{
HtmxTriggerTiming.Receive => _receive ??= new Dictionary<string, object>(),
HtmxTriggerTiming.AfterSettle => _afterSettle ??= new Dictionary<string, object>(),
_ => _afterSwap ??= new Dictionary<string, object>()
HtmxTriggerTiming.AfterSwap => _afterSwap ??= new Dictionary<string, object>(),
_ => _afterSettle ??= new Dictionary<string, object>(),
};

if (events is Dictionary<string, object> dictionary)
Expand All @@ -55,8 +55,8 @@ public void AddEvents(HtmxTriggerTiming timing, IReadOnlyDictionary<string, obje
return timing switch
{
HtmxTriggerTiming.Receive => _receive,
HtmxTriggerTiming.AfterSettle => _afterSettle,
_ => _afterSwap
HtmxTriggerTiming.AfterSwap => _afterSwap,
_ => _afterSettle,
};
}

Expand All @@ -73,11 +73,11 @@ public void SetEvents(HtmxTriggerTiming timing, IReadOnlyDictionary<string, obje
case HtmxTriggerTiming.Receive:
_receive = replacement;
break;
case HtmxTriggerTiming.AfterSettle:
_afterSettle = replacement;
case HtmxTriggerTiming.AfterSwap:
_afterSwap = replacement;
break;
default:
_afterSwap = replacement;
_afterSettle = replacement;
break;
}
}
Expand All @@ -88,8 +88,8 @@ public void SetEvents(HtmxTriggerTiming timing, IReadOnlyDictionary<string, obje
public void Flush()
{
SetHeader(HtmxResponseHeaderNames.Trigger, _receive);
SetHeader(HtmxResponseHeaderNames.TriggerAfterSettle, _afterSettle);
SetHeader(HtmxResponseHeaderNames.TriggerAfterSwap, _afterSwap);
SetHeader(HtmxResponseHeaderNames.TriggerAfterSettle, _afterSettle);
}

/// <summary>
Expand Down
12 changes: 6 additions & 6 deletions src/Ramstack.HtmxToolkit/TagHelpers/HtmxConfigTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ public sealed class HtmxConfigTagHelper(IAntiforgery antiforgery) : TagHelper
[HtmlAttributeName("added-class")]
public string? AddedClass { get; set; }

/// <summary>
/// Gets or sets the settling class. Defaults to <c>htmx-settling</c>.
/// </summary>
[HtmlAttributeName("settling-class")]
public string? SettlingClass { get; set; }

/// <summary>
/// Gets or sets the swapping class. Defaults to <c>htmx-swapping</c>.
/// </summary>
[HtmlAttributeName("swapping-class")]
public string? SwappingClass { get; set; }

/// <summary>
/// Gets or sets the settling class. Defaults to <c>htmx-settling</c>.
/// </summary>
[HtmlAttributeName("settling-class")]
public string? SettlingClass { get; set; }

/// <summary>
/// Gets or sets a value indicating whether eval is allowed.
/// Defaults to <see langword="true" />.
Expand Down
Loading