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

feat(core): Added support for resolving expression functions that return Observables #3744

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Snappey
Copy link

@Snappey Snappey commented Jul 17, 2023

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
Feature

What is the current behavior? (You can also link to an open issue here)
Expressions that are bound the functions that return Observables are not subscribed to, this is a difficult problem to solve as we don't have access to the return type information without executing the bound function which may have side effects.

#1818 and #2013 , there are workarounds but feel less than ideal in certain situations.

What is the new behavior (if this is a feature change)?
Expression keys that end with a '$' are treated as returning an Observable, this allows us to assume their intention and validate this with the additional index signatures.

$ suffix is typically used to represent Observables within the Angular ecosystem so seems natural to make this assumption within the context of a model.

Please check if the PR fulfills these requirements

Please provide a screenshot of this feature before and after your code changes, if applicable.
N/A

Other information:
Appreciate this could be a potentially controversial change but I think it'll be beneficial to at least consider the option going forwards, it unlocks alot more consice field extension and feels natural in my opinion and has been requested throughout the years fairly consistently from what I can see.

I've included an additional page within the Guides/Advanced section demonstrating how Observables can be used in relation ot expression properties.

Look forwards to hearing your thoughts!

Expressions keys that end with $ are treated as returning an Observable value, if the value is a
function it is executed and expected to return an Observable. This allows for accessing the field
data via the parameter in the same manor as typical expression, as well as more complex situations
that may require multiple other observables conditionaly to be resolved.

fix ngx-formly#1818, fix ngx-formly#2013
Several examples of how Observables can be bound to expression properties including returning a
function from an Observable using a key with a $ suffix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant