This repository has been archived by the owner on Aug 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ⚡️ switch to gzipped files * ⚡️ add functional interfaces for components * minor fixes * ⚡️ add session state impl * fix issues with indexing
- Loading branch information
1 parent
7fb41f1
commit e9c6ba9
Showing
16 changed files
with
293 additions
and
225 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,22 @@ | ||
from pydantic import Field | ||
|
||
from schorle.app import Schorle | ||
from schorle.attrs import On | ||
from schorle.component import Component | ||
from schorle.component import component | ||
from schorle.element import button, div | ||
from schorle.reactive import Reactive | ||
from schorle.text import text | ||
|
||
app = Schorle(title="Schorle | Counter App") | ||
|
||
|
||
class Counter(Component): | ||
value: Reactive[int] = Field(default_factory=Reactive.factory(0)) | ||
|
||
def initialize(self): | ||
self.value.subscribe(self.rerender) | ||
|
||
def render(self): | ||
with div(classes="space-x-4"): | ||
with button(on=On("click", self.value.lazy(self.value.rx + 1)), classes="btn btn-primary"): | ||
text("Increment") | ||
@component(state=Reactive.factory(0)) | ||
def counter(state: Reactive[int]): | ||
with div(classes="flex flex-col items-center"): | ||
with button(classes="btn btn-primary", on=On("click", state.lazy(state.rx + 1))): | ||
text("Increment") | ||
with div(classes="text-lg font-semibold text-center m-2"): | ||
text(f"Clicked {self.value.rx} times") | ||
text(f"Clicked {state.rx} times") | ||
|
||
|
||
@app.get("/") | ||
def home_page(): | ||
return Counter() | ||
def index(): | ||
return counter() |
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
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
Oops, something went wrong.