NullVoxPopuli / ember-resources

An implementation of Resources. Supports ember 3.28+
https://github.com/NullVoxPopuli/ember-resources/blob/main/docs/docs/README.md
MIT License
91 stars 37 forks source link

Implement custom usables, `regusterUsable` #1091

Closed NullVoxPopuli closed 6 months ago

NullVoxPopuli commented 6 months ago

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:

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


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

stackblitz[bot] commented 6 months ago

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

github-actions[bot] commented 6 months ago

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
github-actions[bot] commented 6 months ago

Preview URLs

readme: https://d19c001f.ember-resources.pages.dev api docs: https://d19c001f.ember-resources.pages.dev/modules.html