diff --git a/.npmrc b/.npmrc index 6a4052e50..c0cc4f7f0 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,6 @@ public-hoist-pattern[]=*@types* + +# Required because broccoli has hard-coded paths to *all* packages +# not just relevant ones.......... +public-hoist-pattern[]=eslint-plugin* +public-hoist-pattern[]=eslint-config* diff --git a/ember-resources/src/util/function-resource.ts b/ember-resources/src/util/function-resource.ts index 5f1891de3..f5e693636 100644 --- a/ember-resources/src/util/function-resource.ts +++ b/ember-resources/src/util/function-resource.ts @@ -313,8 +313,96 @@ class FunctionResourceManager { } } +type ResourceFactory = (...args: any[]) => ReturnType; + +class ResourceInvokerManager { + capabilities = helperCapabilities('3.23', { + hasValue: true, + hasDestroyable: true, + }); + + createHelper(fn: ResourceFactory, args: any): ReturnType { + // this calls `resource`, which registers + // with the other helper manager + return fn(...args.positional); + } + + getValue(helper: ReturnType) { + let result = invokeHelper(this, helper, () => ({})); + + return getValue(result); + } + + getDestroyable(helper: ReturnType) { + return helper; + } +} + // Provide a singleton manager. const MANAGER = new FunctionResourceManager(); +const ResourceInvoker = new ResourceInvokerManager(); + +/** + * Allows wrapper functions to provide a [[resource]] for use in templates. + * + * Only library authors may care about this, but helper function is needed to "register" + * the wrapper function with a helper manager that specifically handles invoking both the + * resource wrapper function as well as the underlying resource. + * + * _App-devs / consumers may not ever need to know this utility function exists_ + * + * Example using strict mode +