New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

lilliepy-state

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lilliepy-state

state manager for lilliepy framework

  • 0.1
  • PyPI
  • Socket score

Maintainers
1

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!

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc