Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/gossi/ember-command. Integrate your Business Logic with Ember gossi.github.io/ember-command
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293// import Helper from '@ember/component/helper';import { capabilities, setHelperManager } from '@ember/helper';
import { decorate } from '../-private/decorator.ts';// import { getOwner } from '../-private/-owner';import { createCommandInstance } from '../-private/instance.ts';
import type { Commandable, CommandInstance } from '../-private/instance.ts';import type Owner from '@ember/owner';import type { HelperCapabilities } from '@glimmer/interfaces';
// eslint-disable-next-line @typescript-eslint/no-explicit-anytype NonInstanceType<K> = K extends InstanceType<any> ? object : K;type DecoratorKey<K> = K extends string | symbol ? K : never;
interface Args { positional: unknown; named: object;}
type CommandHelperSignature = (owner: Owner, ...commandables: Commandable[]) => CommandInstance;
class CommandHelperManager { capabilities: HelperCapabilities = capabilities('3.23', { hasValue: true });
constructor(private owner: Owner | undefined) {}
createHelper(fn: CommandHelperSignature, args: Args) { return { fn, args }; }
getValue({ fn, args }: { fn: CommandHelperSignature; args: Args }) { // eslint-disable-next-line @typescript-eslint/non-nullable-type-assertion-style return fn(this.owner as Owner, ...(args.positional as Commandable[])); }}
interface DecoratorPropertyDescriptor extends PropertyDescriptor { initializer?(): unknown;}
export default function command(...commandables: Commandable[]): CommandInstance;
/** * The `@use` decorator can be used to use a Resource in javascript classes * * ```js * import { command } from 'ember-resources'; * * class MyC { * @command data = Clock; * } * * ``` */export default function command<Prototype, Key>( prototype: NonInstanceType<Prototype>, key: DecoratorKey<Key>, descriptor?: DecoratorPropertyDescriptor): void;
// commandables: Commandable[] | object,// key?: string | symbol | Owner,// desc?: DecoratorPropertyDescriptor
export default function command( ...args: Parameters<typeof decorate> | [Owner, ...Commandable[]] | Commandable[]): void | CommandInstance { if ( args.length === 3 && ((args[2] as DecoratorPropertyDescriptor).get || (args[2] as DecoratorPropertyDescriptor).initializer) ) { return decorate( args[0], args[1] as string | symbol, args[2] as DecoratorPropertyDescriptor ) as unknown as void; }
return createCommandInstance(args[0] as Owner, args.slice(1) as Commandable[]);
// if (key && desc && (desc.get || desc.initializer)) { // return decorate(undefined, key as string | symbol, desc) as unknown as void; // }
// return createCommandInstance(key as Owner, commandables as Commandable[]);}
setHelperManager((owner) => new CommandHelperManager(owner as Owner), command);