WindowsCommunityToolkit icon indicating copy to clipboard operation
WindowsCommunityToolkit copied to clipboard

Add Evaluate() method to expression nodes

Open arcadiogarcia opened this issue 2 years ago • 1 comments

Fixes

This PR contributes the Evaluate() method proposed in #4481 to evaluate the current value of any ExpresionNode at any given time (see discussion for rationale/usecases)

PR Type

What kind of change does this PR introduce?

  • Feature

What is the current behavior?

Currently consumers of the library can't get the current or hypothetical value of a ExpressionNode without running the animation, and even if they run it is hard to guarantee that the desired result is always returned (the user needs to read the value from the composition api at the right time, which is not always easy, and I've observed cases where the values are stale and haven't been updated by the composer yet).

What is the new behavior?

This PR adds a method that evaluates it by traversing the expression tree. This doesn't alter the current logic/behavior, and the code introduced will only be executed if the consumer calls the Evaluate() method manually.

Also added a small test that verifies that a couple expression nodes evaluate to the right result.

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • [x] Based off latest main branch of toolkit
  • [x] Tested code with current supported SDKs
  • [ ] New component
    • [ ] Pull Request has been submitted to the documentation repository instructions. Link:
    • [ ] Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
    • [ ] If control, added to Visual Studio Design project
  • [ ] Sample in sample app has been added / updated (for bug fixes / features)
  • [ ] New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • [x] Tests for the changes have been added (for bug fixes / features) (if applicable)
  • [x] Header has been added to all new source files (run build/UpdateHeaders.bat)
  • [x] Contains NO breaking changes

Other information

arcadiogarcia avatar May 16 '22 22:05 arcadiogarcia

Thanks arcadiogarcia for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

ghost avatar May 16 '22 22:05 ghost