Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Async to ObservableCollections #1411

Merged
merged 3 commits into from
Aug 17, 2023
Merged

Conversation

thetableman
Copy link
Contributor

This PR adds the ability for an ObservableCollection object to call an awaitable as per discussion #1384.

@falkoschindler I wasn't able to find a way for a ui element to be run within the called awaitable using a parent slot, I also wasn't sure if you wanted the arguments parameter of handle_event to be optional hence why I passed a NoneType.

@falkoschindler falkoschindler self-requested a review August 14, 2023 09:01
@falkoschindler falkoschindler merged commit 7653f25 into zauberzeug:main Aug 17, 2023
1 check passed
@falkoschindler
Copy link
Contributor

Thanks a lot for this PR, @thetableman!
In 1738078 I reviewed and improve the code a little (had to merge first because I couldn't push onto your PR). I basically fix some mypy issues, added a sender to the ObservableChangeEventArguments and made sure to actually use these arguments.

@falkoschindler falkoschindler removed their request for review August 17, 2023 16:25
@falkoschindler falkoschindler added this to the 1.3.10 milestone Aug 17, 2023
@falkoschindler falkoschindler added the enhancement New feature or request label Aug 17, 2023
@falkoschindler
Copy link
Contributor

By the way, can be tested with this code:

from nicegui import events, observables, ui


async def handle_change(e: events.ObservableChangeEventArguments) -> None:
    await asyncio.sleep(0.1)
    with column:
        ui.label(f'Hello {data["name"]}!')
        print(e.sender)

data = observables.ObservableDict({
    'name': 'World',
}, handle_change)

ui.button('Click me', on_click=lambda: data.update(name=data['name'] + '!'))

column = ui.column()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants