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

Implement custom usables, regusterUsable #1091

Merged
merged 8 commits into from
Jan 9, 2024

Conversation

NullVoxPopuli
Copy link
Owner

@NullVoxPopuli NullVoxPopuli commented Jan 9, 2024

This is an important public API to formally support things like ember-modify-based-class-resource, as well as allow others to create usables in their libraries.

registerUsable is a very light wrapper around invokeHelper that allows customization of how args are pasesd to to the "helper"

For example, if ember-concurrency wanted to integrate with the usable system, they could do something like this:

import { macroCondition, dependencySatisfies, importSync } from '@embroider/macros';

if (macroCondition(dependencySatisfies('ember-resources', '>= 7.0.0'))) {
  const { registerUsable } = importSync('ember-resources');
  
  registerUsable('ember-concurrency', (context, config) => {
    const { args, definition } = config;
    return invokeHelper(context, definition, () => /* ... args ... */);
  });
}

Provided that:

  • definition is registered with the helper-manager system.
  • the config object has a type property with value set to ember-concurrency -- in practice this would be a property set on the result of their task function.

registerUsable is used in two places at the time of putting this PR up:

  • in the function-based resource:
    registerUsable(TYPE, (context config) => {
      return invokeHelper(context, config);
    });
  • in the class-based extracted addon, linked above:
    registerUsable(TYPE, (context, config) => {
      let { definition, thunk } = config;
    
      return invokeHelper(context, definition, () => normalizeThunk(thunk));
    });

This PR had a cascading affect which allowed the removal of some old Types that were previously only used for the class-based implementation.

Copy link

stackblitz bot commented Jan 9, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Contributor

github-actions bot commented Jan 9, 2024

Estimated impact to a consuming app, depending on which bundle is imported

js min min + gzip min + brotli
/index.js 18.45 kB 4.39 kB 1.65 kB 1.45 kB

Copy link
Contributor

github-actions bot commented Jan 9, 2024

@NullVoxPopuli NullVoxPopuli merged commit 8818a0e into main Jan 9, 2024
24 checks passed
@NullVoxPopuli NullVoxPopuli deleted the add-support-for-custom-usables branch January 9, 2024 23:33
@github-actions github-actions bot mentioned this pull request Jan 9, 2024
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.

1 participant