Skip to content

Commit

Permalink
Support for custom defer headers
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Feb 10, 2023
1 parent f33a76c commit 2f7e5ba
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/views/functional/defer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
->mergeVueBinding(':url', $url)
}}
@if($data) :default="@js($data)" @else :default="{!! $json !!}" @endif
@if($headers) :headers="@js($headers)" @else :headers="{!! $jsonHeaders !!}" @endif
@if($requestData) :request="@js($requestData)" @else :request="{!! $requestJson !!}" @endif>
<template #default="{!! $scope !!}">
{{ $slot }}
Expand Down
21 changes: 19 additions & 2 deletions src/Components/Defer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class Defer extends Component

public $requestJson;

public $headers;

public $jsonHeaders;

/**
* Create a new component instance.
*
Expand All @@ -32,6 +36,7 @@ public function __construct(
public bool $manual = false,
public string $scope = '{ processing, response, reload }',
public string $url = '',
$headers = null
) {
$parsed = $this->parseJsonData($default);

Expand All @@ -54,6 +59,16 @@ public function __construct(
if (!Str::startsWith($url, '`') && !Str::endsWith($url, '`')) {
$this->url = Js::from($url);
}

//

$parsed = $this->parseJsonData($headers);

if ($parsed) {
$this->headers = $parsed;
} else {
$this->jsonHeaders = $headers ?: '{}';
}
}

/**
Expand All @@ -64,8 +79,10 @@ public function __construct(
public function render()
{
return view('splade::functional.defer', [
'data' => $this->data,
'json' => $this->json,
'data' => $this->data,
'json' => $this->json,
'headers' => $this->headers,
'jsonHeaders' => $this->jsonHeaders,
]);
}
}

0 comments on commit 2f7e5ba

Please sign in to comment.