Created
July 29, 2023 11:42
-
-
Save thekid/019b12627f129afe7bdaea4cc594b29a to your computer and use it in GitHub Desktop.
HTMX and the XP Framework
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 web\Application; | |
use web\frontend\{Frontend, Handlebars, Get, Post, Delete, Param, View}; | |
class Reactive extends Application { | |
public function routes() { | |
$impl= new class() { | |
private $list= ['One', 'Two']; | |
#[Get] | |
public function view() { | |
return View::named('reactive')->with(['items' => $this->list]); | |
} | |
#[Post('/fragment/listing')] | |
public function add(#[Param] $name) { | |
$this->list[]= $name; | |
return View::named('reactive')->fragment('listing')->with(['items' => $this->list]); | |
} | |
#[Delete('/fragment/listing')] | |
public function remove(#[Param] $id) { | |
unset($this->list[$id]); | |
return View::named('reactive')->fragment('listing')->with(['items' => $this->list]); | |
} | |
}; | |
return new Frontend($impl, new Handlebars('.')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment