This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class VehicleServiceBinder | |
{ | |
//Singleton Pattern | |
private static $instance; | |
public static function getVehicleService() | |
{ | |
if (self::$instance == null) { | |
self::$instance = new FooVehicleService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
class FooVehicleService implements IVehicleService | |
{ | |
public function find($vehicleNumber) | |
{ | |
//logic to find Vehicle, probably in database | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
interface IVehicleService | |
{ | |
public function find($vehicleNumber); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
class VehicleSearchController extends Controller | |
{ | |
public function searchVehicle(VehicleSearchRequest $request) | |
{ | |
$data = $request->validated(); | |
//Instantiate (FooVehicleService is directly EXPOSED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services; | |
class FooVehicleService | |
{ | |
public function find($vehicleNumber) | |
{ | |
//logic to find Vehicle, probably in database | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getDataFromServer(repo: string) { | |
//2 seconds delay, just for explaination | |
var n = 3 + Math.floor(Math.random() * 5); | |
await timeout(n * 1000); | |
const res = await fetch("https://api.github.com/users/" + repo, { | |
cache: "force-cache", | |
}); | |
if (!res.ok) { | |
throw new Error("Failed to fetch data : " + res.status); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function RepoComponentLoading() { | |
return ( | |
<main className="p-5 border-red-100 "> | |
<table className="table-fixed"> | |
<tbody> | |
<tr> | |
<th className="border border-slate-300 p-3">Login</th> | |
<td className="border border-slate-300 p-3"> ..... </td> | |
</tr> | |
<tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RepoComponent from "@/components/repo-component"; | |
import RepoComponentLoading from "@/components/repo-component-loading"; | |
import { Suspense } from "react"; | |
export default function Home() { | |
return ( | |
<main className="p-10 "> | |
<div className="flex flex-row"> | |
<Suspense fallback={<RepoComponentLoading />}> | |
<RepoComponent slug="twitter" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Livewire\Volt\Component; | |
use Livewire\Attributes\Rule; | |
new class extends Component { | |
#[Rule(['required', 'numeric'])] | |
public $inputvalue = 0; | |
public $result = null; | |
public function updateResult() | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Livewire\Volt\Component; | |
use Livewire\Attributes\Rule; | |
new class extends Component { | |
public $count = 0; | |
public function decrement() | |
{ | |
$this->count--; | |
} | |
public function increment() |