@@ -144,7 +144,14 @@ public HtmxResponse ReplaceUrl(string url)
144
144
/// <returns>This <see cref="HtmxResponse"/> object instance.</returns>
145
145
public HtmxResponse Reswap ( string modifier )
146
146
{
147
- headers [ HtmxResponseHeaderNames . Reswap ] = modifier ;
147
+ if ( string . IsNullOrWhiteSpace ( modifier ) )
148
+ {
149
+ headers . Remove ( HtmxResponseHeaderNames . Reswap ) ;
150
+ }
151
+ else
152
+ {
153
+ headers [ HtmxResponseHeaderNames . Reswap ] = modifier ;
154
+ }
148
155
149
156
return this ;
150
157
}
@@ -159,37 +166,35 @@ public HtmxResponse Reswap(SwapStyle swapStyle, string? modifier = null)
159
166
{
160
167
AssertIsHtmxRequest ( ) ;
161
168
162
- var style = swapStyle switch
169
+ if ( swapStyle is SwapStyle . Default )
163
170
{
164
- SwapStyle . InnerHTML => "innerHTML" ,
165
- SwapStyle . OuterHTML => "outerHTML" ,
166
- SwapStyle . BeforeBegin => "beforebegin" ,
167
- SwapStyle . AfterBegin => "afterbegin" ,
168
- SwapStyle . BeforeEnd => "beforeend" ,
169
- SwapStyle . AfterEnd => "afterend" ,
170
- SwapStyle . Delete => "delete" ,
171
- SwapStyle . None => "none" ,
172
- _ => throw new SwitchExpressionException ( swapStyle ) ,
173
- } ;
171
+ Reswap ( modifier ) ;
172
+ return this ;
173
+ }
174
174
175
- var value = modifier != null ? $ "{ style } { modifier } " : style ;
175
+ var style = swapStyle . ToHtmxString ( ) ;
176
+ var value = ! string . IsNullOrWhiteSpace ( modifier )
177
+ ? $ "{ style } { modifier } "
178
+ : style ;
176
179
177
180
headers [ HtmxResponseHeaderNames . Reswap ] = value ;
178
181
179
182
return this ;
180
183
}
181
184
182
185
/// <summary>
183
- /// Allows you to specify how the response will be swapped.
186
+ /// Allows you to specify how the response will be swapped.
184
187
/// </summary>
185
188
/// <param></param>
186
189
/// <param name="swapStyle"></param>
187
- /// <returns></returns>
190
+ /// <returns>This <see cref="HtmxResponse"/> object instance. </returns>
188
191
public HtmxResponse Reswap ( SwapStyleBuilder swapStyle )
189
192
{
190
- var ( style , modifier ) = swapStyle . Build ( ) ;
193
+ var ( style , modifier ) = swapStyle . Build ( ) ;
191
194
192
- return style is null ? Reswap ( modifier ) : Reswap ( ( SwapStyle ) style , modifier ) ;
195
+ return style is SwapStyle . Default
196
+ ? Reswap ( modifier )
197
+ : Reswap ( style , modifier ) ;
193
198
}
194
199
195
200
/// <summary>
@@ -224,11 +229,12 @@ public HtmxResponse Reselect(string selector)
224
229
/// Sets response code to stop polling
225
230
/// </summary>
226
231
/// <returns></returns>
232
+ /// <returns>This <see cref="HtmxResponse"/> object instance.</returns>
227
233
public HtmxResponse StopPolling ( )
228
234
{
229
- context . Response . StatusCode = HtmxStatusCodes . StopPolling ;
235
+ context . Response . StatusCode = HtmxStatusCodes . StopPolling ;
230
236
231
- return this ;
237
+ return this ;
232
238
}
233
239
234
240
/// <summary>
@@ -314,7 +320,7 @@ public override string ToString()
314
320
315
321
private void AssertIsHtmxRequest ( )
316
322
{
317
- if ( ! isHtmxRequest )
323
+ if ( ! isHtmxRequest )
318
324
{
319
325
throw new InvalidOperationException (
320
326
"The active request is not an htmx request. " +
0 commit comments