Skip to main content

state manager for lilliepy framework

Project description

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.

# 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.

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.

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.

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

@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!

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lilliepy_state-0.1.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lilliepy_state-0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file lilliepy_state-0.1.tar.gz.

File metadata

  • Download URL: lilliepy_state-0.1.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for lilliepy_state-0.1.tar.gz
Algorithm Hash digest
SHA256 076116732f8c8bd940a2ba6d28b226d091a336586c8b6db470bff0efa7e8ff99
MD5 795eac6e90f38228a0e60db399b11737
BLAKE2b-256 8adbe4c816bd683aa000f6fcd1b0093be79f97b161d3075b55b688aaf8bae78c

See more details on using hashes here.

File details

Details for the file lilliepy_state-0.1-py3-none-any.whl.

File metadata

  • Download URL: lilliepy_state-0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for lilliepy_state-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 52232bbab3bbee6d901baf5527cd2c07bc0164e6d7cd5b5f8fdc15c8ec7c0a39
MD5 2bc2fef800740b8ddfe795c93e311d69
BLAKE2b-256 f4a78836b1de58271f4d818e0d221201af231555935d1e2f6ffc691874916c97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page