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

Introduce eager option to function-based modifiers #222

Merged
merged 6 commits into from
Mar 25, 2022

Conversation

chriskrycho
Copy link
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 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.
This allows existing places people are exlpicitly using the type to
continue to work with the looser type supplied via `ArgsFor`.
addon/-private/functional/modifier.ts Outdated Show resolved Hide resolved
Since the number of options is limited, we can just create one
instance for the two scenarios we care about.
addon/-private/functional/modifier.ts Outdated Show resolved Hide resolved
addon/-private/functional/modifier.ts Outdated Show resolved Hide resolved
addon/-private/functional/modifier.ts Outdated Show resolved Hide resolved
addon/-private/functional/modifier.ts Outdated Show resolved Hide resolved
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.

None yet

2 participants