Skip to content

Introduce eager option to function-based modifiers#222

Merged
rwjblue merged 6 commits intomasterfrom
function-base-modifier-eager
Mar 25, 2022
Merged

Introduce eager option to function-based modifiers#222
rwjblue merged 6 commits intomasterfrom
function-base-modifier-eager

Conversation

@chriskrycho
Copy link
Copy Markdown
Contributor

@chriskrycho chriskrycho commented Mar 24, 2022

Introduce an options argument to the modifier() function used to create function-based modifiers, with a single initial option: eager. Passing { eager: false } opts out of the previous default beahvior of eagerly consuming all arguments, so that function-based modifiers can have normal auto-tracking semantics -- that is, only rerunning when the tracked state they use changes. This allows users to opt into the new (eager: false) behavior on a per-modifier basis.

There are three changes to accompany the new options object here:

  1. Add overloads to modifier for the following cases:

    • the user passes no options (the default up till now)
    • the user passes { eager: true } (matching the previous default)
    • the user passes { eager: false } (the new target behavior)

    These overloads intentionally do not support invoking with a "signature" for { eager: false }. If users want to introduce an explicit signature for function-based modifiers, they should first convert to the { eager: false } semantics.

  2. Update the function-based modifier manager internals to support this. As a result, we now need to create a new instance each time, with the corresponding options.

  3. Update the internals of the function-based modifier manager to use a state bucket, aligning it with the internals of the class-based modifier manager and getting rid of the need for Maps for keeping track of modifier elements and teardowns.


(Docs and deprecation of the legacy behavior will follow!)

@chriskrycho chriskrycho added the enhancement New feature or request label Mar 24, 2022
@chriskrycho chriskrycho requested a review from rwjblue March 24, 2022 02:09
@chriskrycho chriskrycho force-pushed the function-base-modifier-eager branch 2 times, most recently from 611a008 to e24b69c Compare March 24, 2022 02:16
Introduce an options argument to the `modifier()` function used to
create function-based modifiers, with a single initial option: `eager`.
Passing `{ eager: false }` opts out of the previous default beahvior of
eagerly consuming all arguments, so that function-based modifiers can
have normal auto-tracking semantics -- that is, only rerunning when the
tracked state they use changes. This allows users to opt into the new
(`eager: false`) behavior on a per-modifier basis.

There are three changes to accompany the new options object here:

1.  Add overloads to `modifier` for the following cases:

    - the user passes no options (the default up till now)
    - the user passes `{ eager: true }` (matching the previous default)
    - the user passes `{ eager: false }` (the new target behavior)

    These overloads intentionally do *not* support invoking with a
    "signature" for `{ eager: false }`. If users want to introduce an
    explicit signature for function-based modifiers, they should first
    convert to the `{ eager: false }` semantics.

2.  Update the function-based modifier manager internals to support
    this. As a result, we now need to create a new instance each time,
    with the corresponding options.

3.  Update the internals of the function-based modifier manager to use
    a state bucket, aligning it with the internals of the class-based
    modifier manager and getting rid of the need for `Map`s for keeping
    track of modifier elements and teardowns.
@chriskrycho chriskrycho force-pushed the function-base-modifier-eager branch from e24b69c to f67d218 Compare March 24, 2022 14:23
This allows existing places people are exlpicitly using the type to
continue to work with the looser type supplied via `ArgsFor`.
@chriskrycho chriskrycho force-pushed the function-base-modifier-eager branch from 3a5b7d2 to 43eafa9 Compare March 24, 2022 19:25
Since the number of options is limited, we can just create one
instance for the two scenarios we care about.
@chriskrycho chriskrycho force-pushed the function-base-modifier-eager branch from f3c5a6f to f4b946d Compare March 25, 2022 16:23
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.

2 participants