Skip to content

v0.12.0

Latest
Compare
Choose a tag to compare
@cofin cofin released this 23 Dec 05:40

What's Changed

  • feat: adds lazy support for inertia by @cofin in #61

** Note ** This adds experimental support for deferring the rendering of props until the request is rendered. This allows you to use the partial data component of inertia to optional request/refresh data.

The function is titled lazy and accepts 2 parameters: A string based "key" and the value or function (sync or async) to defer:

async def basic_example_of_lazy_rendering() -> None:
    def simulated_expensive_sync_function() -> str:
        sleep(0.5)
        return "callable_result"

    async def simulated_expensive_async_function() -> str:
        await asyncio.sleep(0.5)
        return "async_result"

    lazy_future_for_sync_method = lazy("test_prop_1", simulated_expensive_sync_function)
    assert lazy_future_for_sync_method.render(portal) == "callable_result"
    
    lazy_future_for_async_method = lazy("test_prop_2", simulated_expensive_async_function)
    assert lazy_future_for_async_method.render(portal) == "async_result"

Full Changelog: v0.11.1...v0.12.0