Skip to content

v0.6.8

Latest
Compare
Choose a tag to compare
@masenf masenf released this 10 Jan 17:27
fea0ceb

New Features

New API: rx.EventChain.create

This new interface makes it easier to transform EventType (EventHandler, EventSpec, and lambda - as accepted by component event triggers) into EventChain to be rendered in hook calls or rx.call_script / rx.call_function invocations.

  • Move _create_event_chain to EventChain.create by @masenf in #4557

New API: BaseState.get_var_value

Similar to get_state, this API provides access to a Var defined in another state. If the value is mutable, changing it will be reflected in the other state. This API is intended for use with ComponentState implementations that want to "borrow" data from another state.

Show Example Code

from typing import ClassVar

import reflex as rx


class MyState(rx.State):
    data: list[dict] = []


class Appender(rx.ComponentState):
    _data: ClassVar[rx.Var]

    async def add_value(self, form_data: dict):
        (await self.get_var_value(self._data)).append(form_data)

    @classmethod
    def get_component(cls, data: rx.Var[list[dict]]) -> rx.Component:
        cls._data = data
        return rx.card(
            rx.form(
                rx.vstack(
                    rx.input(placeholder="Name", name="name", autofocus=True),
                    rx.input(placeholder="Email", name="email"),
                    rx.button("Submit", type="submit"),
                ),
                reset_on_submit=True,
                on_submit=cls.add_value,
            ),
        )


appender = Appender.create


def index() -> rx.Component:
    return rx.vstack(
        rx.foreach(
            MyState.data,
            lambda d: rx.text(d.to_string()),
        ),
        appender(data=MyState.data),
    )


app = rx.App()
app.add_page(index)
  • BaseState.get_var_value helper to get a value from a Var by @masenf in #4553

Improvements

Add .endswith() var operation for strings

Simpler API for rx._x.client_state

Use client state vars anywhere in the tree instead of having to include them and use them separately.

Support Recursive UI elements with @rx.memo

See example code in PR. This allows the rendering of trees and other self-referential structures using rx.foreach.

Performance

Miscellaneous

  • fix health check and skip not needed tasks by @Lendemor in #4563
  • [ENG-4083] Track internal changes in dataclass instances by @masenf in #4558
  • use position in vardata to mark internal hooks by @Lendemor in #4549
  • Enable automatic retry on redis errors by @masenf in #4595

Bug Fixes

  • Add expire_on_commit=False for async sessions by @masenf in #4582
  • Do not allow call_function callback argument to be added afterwards by @masenf in #4552
  • [ENG-2157] [Refix] Allow rx.download to resolve rx.get_upload_url by @masenf in #4470
  • fixes #4578 - correct the way dim_props created by @KanvaBhatia in #4587
  • unbreak link _hover by @masenf in #4537
  • [ENG-4255] Code blocks lead to redefined const in web page by @masenf in #4598

Version Bumps

Documentation

Other Changes

New Contributors

Full Changelog: v0.6.7...v0.6.8