emilhe / dash-extensions

The dash-extensions package is a collection of utility functions, syntax extensions, and Dash components that aim to improve the Dash development experience
https://www.dash-extensions.com/
MIT License
409 stars 57 forks source link

Trigger for clientside callbacks #318

Closed frnhr closed 2 months ago

frnhr commented 3 months ago

From TriggerTransform:

NOTE: This transform cannot be implemented for clientside callbacks since the JS can't be modified from here.

I respectfully beg to differ.

We can wrap the callback JS function in another function which takes out the trigger args.

Roughly like this:

// original callback:
function(important, _irrelevant, interesting) {
    return important * interesting;
}

// wrapped callback:
function(important, _irrelevant, interesting) {
    const func = function(important, interesting) {  // <-- '_irrelevent' removed
        return important * interesting;
    };
    return func(important, interesting);
}

Implementation is in this PR.

codecov[bot] commented 3 months ago

Codecov Report

Attention: Patch coverage is 83.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 77.75%. Comparing base (1e70fed) to head (38c2324).

Files Patch % Lines
dash_extensions/enrich.py 83.33% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #318 +/- ## ========================================== + Coverage 77.69% 77.75% +0.06% ========================================== Files 11 11 Lines 1058 1070 +12 ========================================== + Hits 822 832 +10 - Misses 236 238 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

emilhe commented 2 months ago

Ah, yes, you are correct! Very elegant solution - I didn't think of that at the time ;)