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

Additions to the .rx namespace #906

Merged
merged 15 commits into from
Mar 6, 2024
Merged

Additions to the .rx namespace #906

merged 15 commits into from
Mar 6, 2024

Conversation

philippjfr
Copy link
Member

@philippjfr philippjfr commented Feb 5, 2024

As we have started building applications with rx a few gaps have become clear, specifically the following functionality is currently missing:

  • Allow constructing "empty" rx() which initializes with a None value
  • Currently there is no way to get the equivalent to the not keyword, therefore we introduce .rx.not_
  • It is quite awkward to apply a function to each item in an iterable, therefore we introduce .rx.map
  • Currently there is no way to achieve equivalent to the and keyword, therefore we introduce .rx.and_
  • Currently there is no way to achieve equivalent to the or keyword, therefore we introduce .rx.or_
  • Add support for an initial value on .param.when so that the expression isn't evaluated until the first event is triggered
  • Allow .rx.watch() without args to make expression evaluate eagerly
  • Update docs

@jbednar
Copy link
Member

jbednar commented Feb 5, 2024

Thanks. Not sure how we missed some of those earlier. The doc page also needs updating.

@philippjfr
Copy link
Member Author

Thanks. Not sure how we missed some of those earlier. The doc page also needs updating.

I did not fully appreciate that and, or and not cannot be overloaded in Python, only the equivalent boolean operators &, | and ~ can.

@MarcSkovMadsen
Copy link
Collaborator

Why are the underscores needed?

@jbednar
Copy link
Member

jbednar commented Feb 6, 2024

Python keywords cannot be identifiers.

@philippjfr philippjfr added this to the 2.1.0 milestone Mar 4, 2024
Copy link
Member

@jbednar jbednar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me now, thanks!

param/reactive.py Outdated Show resolved Hide resolved
Co-authored-by: James A. Bednar <jbednar@continuum.io>
doc/user_guide/Reactive_Expressions.ipynb Outdated Show resolved Hide resolved
"id": "7eac3901-b9e6-4020-8f74-5817561a187e",
"metadata": {},
"source": [
"When we update the expression the `updating` expression will temporarily toggle to True and then reset:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to hook into this updating? An example of this could be adding a loading spinner in Panel if more than 1 second has passed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quite difficult since most of the time whatever action that is performing the update will be blocking which means you can't simultaneously perform throttling or debouncing on the event.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it, since now I want this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will only work for async callbacks and generators though.

param/reactive.py Outdated Show resolved Hide resolved
param/reactive.py Outdated Show resolved Hide resolved
param/reactive.py Show resolved Hide resolved
param/reactive.py Outdated Show resolved Hide resolved
param/reactive.py Show resolved Hide resolved
param/reactive.py Outdated Show resolved Hide resolved
tests/testreactive.py Show resolved Hide resolved
Copy link
Member

@maximlt maximlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@hoxbro hoxbro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than Maxime suggestion LGTM.

@philippjfr philippjfr merged commit 893f953 into main Mar 6, 2024
10 checks passed
@philippjfr philippjfr deleted the rx_enhance branch March 6, 2024 17:38
@philippjfr philippjfr mentioned this pull request Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants