Alfort-DOM
Alfort-DOM is Elm-like web application framework for Python. It uses Alfort to handle Vritual DOM and Pyodide to run its codes on browser.
Installation
$ pip install alfort-dom
Example
from dataclasses import dataclass
from typing import TypeAlias
from alfort import Effect
from alfort.vdom import VDom, el
from alfort_dom import AlfortDom
@dataclass(frozen=True)
class CountUp:
value: int = 1
@dataclass(frozen=True)
class CountDown:
value: int = 1
Msg: TypeAlias = CountUp | CountDown
def title(text: str) -> VDom:
return el("h1", {}, [text])
def count(cnt: int) -> VDom:
return el("div", {"style": {"margin": "8px"}}, [str(cnt)])
def buttons() -> VDom:
button_style = {"margin": "4px", "width": "50px"}
return el(
"div",
{},
[
el("button", {"style": button_style, "onclick": CountDown(10)}, ["-10"]),
el("button", {"style": button_style, "onclick": CountDown()}, ["-"]),
el("button", {"style": button_style, "onclick": CountUp()}, ["+"]),
el("button", {"style": button_style, "onclick": CountUp(10)}, ["+10"]),
],
)
def view(state: dict[str, int]) -> VDom:
return el(
"div",
{
"style": {
"display": "flex",
"justify-content": "center",
"align-items": "center",
"flex-flow": "column",
}
},
[title("Simple Counter"), count(state["count"]), buttons()],
)
def init() -> tuple[dict[str, int], list[Effect[Msg]]]:
return ({"count": 0}, [])
def update(msg: Msg, state: dict[str, int]) -> tuple[dict[str, int], list[Effect[Msg]]]:
match msg:
case CountUp(value):
return ({**state, "count": state["count"] + value}, [])
case CountDown(value):
return ({**state, "count": state["count"] - value}, [])
app = AlfortDom[dict[str, int], Msg](
init=init,
view=view,
update=update,
)
app.main(root="root")
If you need more exmplaes, please check the examples.
For development
Install Poery plugins
$ poetry self add "poethepoet[poetry_plugin]"
Run tests
$ poetry poe test
Run linter and formatter
$ poetry poe check
Run examples
$ poetry poe run-example
See Also
License
Metadata
Release files for alfort-dom 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| alfort_dom-0.1.3.tar.gz | 10.5 kB | Without provenance | Details for alfort_dom-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| alfort_dom-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for alfort_dom-0.1.3-py3-none-any.whl |
Total release size: 21.4 kB
Release files / alfort_dom-0.1.3.tar.gz
| Download URL | alfort_dom-0.1.3.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1c4173a6d0a26f5010206833801c074c3fbb3b0612c5957817911b9bc791f3bb
|
|
BLAKE2b-256 checksum How to use checksums |
53691176d9471d130c1aecd4f42d16086df4ee05e6a507afee0bb669e5d80ed1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.7 Linux/5.15.0-1020-azure
|
Release files / alfort_dom-0.1.3-py3-none-any.whl
| Download URL | alfort_dom-0.1.3-py3-none-any.whl |
|---|---|
| Size | 10.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
74f4e9cfb58a7fb9732402c884d9587768b5ecad4e11107e4225f98d8b95f834
|
|
BLAKE2b-256 checksum How to use checksums |
b7f026ad81e12aeb0d4def1962207b763aed76946298f69304522388f81a875a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.7 Linux/5.15.0-1020-azure
|
Security for alfort-dom 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.