lilliepy-state


Namelilliepy-state JSON
Version 0.1 PyPI version JSON
download
home_pagehttps://github.com/websitedeb/lilliepy-state
Summarystate manager for lilliepy framework
upload_time2024-12-26 02:47:05
maintainerNone
docs_urlNone
authorSarthak Ghoshal
requires_python>=3.6
licenseMIT
keywords lilliepy lilliepy-state reactpy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # liiliepy State Management Library

A lightweight state management library for lilliepy, inspired by state management solutions like Zustand and XState.

---

## Features

1. **State Containers**: Manage global or local state in an intuitive way.
2. **Selectors**: Derive state slices to minimize unnecessary re-renders.
3. **Transitions**: (Optional) Add finite state machine (FSM) logic for more complex scenarios.

---

## Installation

Simply include the `liiliepy_state.py` file in your project.

```bash
# Clone the repository (if applicable)
git clone <repository_url>
```

---

## Quick Start

### 1. Define a Store

Create a state container to manage your application's state.

```python
from liiliepy_state import StateContainer

# Define your store
counter_store = StateContainer({"count": 0})

# Define actions
def increment():
    counter_store.set_state(lambda state: {"count": state["count"] + 1})

def decrement():
    counter_store.set_state(lambda state: {"count": state["count"] - 1})
```

---

### 2. Use the Store in liiliepy Components

Connect your store to liiliepy components using the `use_store` hook.

```python
from reactpy import component, html
from liiliepy_state import use_store
from my_store import counter_store, increment, decrement

@component
def CounterComponent():
    state, _ = use_store(counter_store)

    return html.div(
        html.button({"onClick": lambda: decrement()}, "-"),
        html.span(f"Count: {state['count']}"),
        html.button({"onClick": lambda: increment()}, "+"),
    )
```

---

### 3. Advanced Usage: Finite State Machines (FSM)

For more complex scenarios, use the `FSMContainer` to add finite state transitions.

```python
from liiliepy_state import FSMContainer

# Define state transitions
fsm_store = FSMContainer("idle", {
    "idle": {"START": "running"},
    "running": {"STOP": "idle"},
})

# Transition actions
def start():
    fsm_store.transition("START")

def stop():
    fsm_store.transition("STOP")
```

#### Component Example

```python
@component
def FSMComponent():
    state, _ = use_store(fsm_store)

    return html.div(
        html.span(f"State: {state}"),
        html.button({"onClick": lambda: start()}, "Start"),
        html.button({"onClick": lambda: stop()}, "Stop"),
    )
```

---

## Roadmap

- **Middleware Support**: Add features like logging and persistence.
- **Optimizations**: Improve performance for concurrent updates.
- **Testing**: Cover edge cases and stress-test the library.

---

## License

This project is licensed under the MIT License. Feel free to use and contribute!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/websitedeb/lilliepy-state",
    "name": "lilliepy-state",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "lilliepy, lilliepy-state, reactpy",
    "author": "Sarthak Ghoshal",
    "author_email": "sarthak22.ghoshal@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8a/db/e4c816bd683aa000f6fcd1b0093be79f97b161d3075b55b688aaf8bae78c/lilliepy_state-0.1.tar.gz",
    "platform": null,
    "description": "# liiliepy State Management Library\r\n\r\nA lightweight state management library for lilliepy, inspired by state management solutions like Zustand and XState.\r\n\r\n---\r\n\r\n## Features\r\n\r\n1. **State Containers**: Manage global or local state in an intuitive way.\r\n2. **Selectors**: Derive state slices to minimize unnecessary re-renders.\r\n3. **Transitions**: (Optional) Add finite state machine (FSM) logic for more complex scenarios.\r\n\r\n---\r\n\r\n## Installation\r\n\r\nSimply include the `liiliepy_state.py` file in your project.\r\n\r\n```bash\r\n# Clone the repository (if applicable)\r\ngit clone <repository_url>\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n### 1. Define a Store\r\n\r\nCreate a state container to manage your application's state.\r\n\r\n```python\r\nfrom liiliepy_state import StateContainer\r\n\r\n# Define your store\r\ncounter_store = StateContainer({\"count\": 0})\r\n\r\n# Define actions\r\ndef increment():\r\n    counter_store.set_state(lambda state: {\"count\": state[\"count\"] + 1})\r\n\r\ndef decrement():\r\n    counter_store.set_state(lambda state: {\"count\": state[\"count\"] - 1})\r\n```\r\n\r\n---\r\n\r\n### 2. Use the Store in liiliepy Components\r\n\r\nConnect your store to liiliepy components using the `use_store` hook.\r\n\r\n```python\r\nfrom reactpy import component, html\r\nfrom liiliepy_state import use_store\r\nfrom my_store import counter_store, increment, decrement\r\n\r\n@component\r\ndef CounterComponent():\r\n    state, _ = use_store(counter_store)\r\n\r\n    return html.div(\r\n        html.button({\"onClick\": lambda: decrement()}, \"-\"),\r\n        html.span(f\"Count: {state['count']}\"),\r\n        html.button({\"onClick\": lambda: increment()}, \"+\"),\r\n    )\r\n```\r\n\r\n---\r\n\r\n### 3. Advanced Usage: Finite State Machines (FSM)\r\n\r\nFor more complex scenarios, use the `FSMContainer` to add finite state transitions.\r\n\r\n```python\r\nfrom liiliepy_state import FSMContainer\r\n\r\n# Define state transitions\r\nfsm_store = FSMContainer(\"idle\", {\r\n    \"idle\": {\"START\": \"running\"},\r\n    \"running\": {\"STOP\": \"idle\"},\r\n})\r\n\r\n# Transition actions\r\ndef start():\r\n    fsm_store.transition(\"START\")\r\n\r\ndef stop():\r\n    fsm_store.transition(\"STOP\")\r\n```\r\n\r\n#### Component Example\r\n\r\n```python\r\n@component\r\ndef FSMComponent():\r\n    state, _ = use_store(fsm_store)\r\n\r\n    return html.div(\r\n        html.span(f\"State: {state}\"),\r\n        html.button({\"onClick\": lambda: start()}, \"Start\"),\r\n        html.button({\"onClick\": lambda: stop()}, \"Stop\"),\r\n    )\r\n```\r\n\r\n---\r\n\r\n## Roadmap\r\n\r\n- **Middleware Support**: Add features like logging and persistence.\r\n- **Optimizations**: Improve performance for concurrent updates.\r\n- **Testing**: Cover edge cases and stress-test the library.\r\n\r\n---\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. Feel free to use and contribute!\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "state manager for lilliepy framework",
    "version": "0.1",
    "project_urls": {
        "Homepage": "https://github.com/websitedeb/lilliepy-state"
    },
    "split_keywords": [
        "lilliepy",
        " lilliepy-state",
        " reactpy"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4a78836b1de58271f4d818e0d221201af231555935d1e2f6ffc691874916c97",
                "md5": "2bc2fef800740b8ddfe795c93e311d69",
                "sha256": "52232bbab3bbee6d901baf5527cd2c07bc0164e6d7cd5b5f8fdc15c8ec7c0a39"
            },
            "downloads": -1,
            "filename": "lilliepy_state-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2bc2fef800740b8ddfe795c93e311d69",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 3185,
            "upload_time": "2024-12-26T02:47:02",
            "upload_time_iso_8601": "2024-12-26T02:47:02.820106Z",
            "url": "https://files.pythonhosted.org/packages/f4/a7/8836b1de58271f4d818e0d221201af231555935d1e2f6ffc691874916c97/lilliepy_state-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8adbe4c816bd683aa000f6fcd1b0093be79f97b161d3075b55b688aaf8bae78c",
                "md5": "795eac6e90f38228a0e60db399b11737",
                "sha256": "076116732f8c8bd940a2ba6d28b226d091a336586c8b6db470bff0efa7e8ff99"
            },
            "downloads": -1,
            "filename": "lilliepy_state-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "795eac6e90f38228a0e60db399b11737",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 3192,
            "upload_time": "2024-12-26T02:47:05",
            "upload_time_iso_8601": "2024-12-26T02:47:05.286680Z",
            "url": "https://files.pythonhosted.org/packages/8a/db/e4c816bd683aa000f6fcd1b0093be79f97b161d3075b55b688aaf8bae78c/lilliepy_state-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-26 02:47:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "websitedeb",
    "github_project": "lilliepy-state",
    "github_not_found": true,
    "lcname": "lilliepy-state"
}
        
Elapsed time: 0.43042s