Options
All
  • Public
  • Public/Protected
  • All
Menu

Class TaskResource<Args, Return, LocalTask>

Type parameters

  • Args: any[]

  • Return

  • LocalTask: TaskIsh<Args, Return>

Hierarchy

  • Resource<{ positional: Args }>
    • TaskResource

Index

Constructors

  • new TaskResource<Args, Return, LocalTask>(owner: unknown): TaskResource<Args, Return, LocalTask>

Properties

[TASK]: LocalTask
currentTask: TaskInstance<Return>
lastTask: undefined | TaskInstance<Return>
of: <Instance, Args>(context: object, klass: new (...args: unknown[]) => Instance, thunk?: Thunk | (() => Args)) => Instance = resourceOf

For use in the body of a class.

Type declaration

    • <Instance, Args>(context: object, klass: new (...args: unknown[]) => Instance, thunk?: Thunk | (() => Args)): Instance
    • For use in the body of a class.

      note

      prefer from

      of is what allows resources to be used in JS, they hide the reactivity APIs from the consumer so that the surface API is smaller. Though, from an end-user-api ergonomics perspective, you wouldn't typically want to rely on this. As in ember-data-resources

      Given this potential use:

      import { Resource } from 'ember-resources';

      class SomeResource extends Resource {}

      class MyClass {
      data = Resource.of(this, SomeResource, () => [arg list]);
      }

      a better user-facing api, may be provided by:

      export function someResource(context, args) {
      return Resource.of(context, SomeResource, () => ... );
      }

      usage:

      import { someResource } from 'your-library';

      class SomeResource extends Resource {}

      class MyClass {
      data = someResource(this, () => [arg list]);
      }

      When any tracked data in the args thunk is updated, the Resource will be updated as well

      • The this is to keep track of destruction -- so when MyClass is destroyed, all the resources attached to it can also be destroyed.
      • The resource will do nothing until it is accessed. Meaning, if you have a template that guards access to the data, like:
        {{#if this.isModalShowing}}
        <Modal>{{this.data.someProperty}}</Modal>
        {{/if}}
        the Resource will not be instantiated until isModalShowing is true.

      Type parameters

      • Instance: Resource<ArgsWrapper, Instance>

      • Args: unknown[] = unknown[]

      Parameters

      • context: object
      • klass: new (...args: unknown[]) => Instance
          • new (...args: unknown[]): Instance
          • Parameters

            • Rest ...args: unknown[]

            Returns Instance

      • Optional thunk: Thunk | (() => Args)

      Returns Instance

Accessors

  • get value(): undefined | null | Return
  • Returns undefined | null | Return

Methods

  • modify(positional: Args): void
  • teardown(): void
  • Returns void

  • from<Instance>(context: object, thunk?: Thunk | (() => unknown)): Instance
  • For use in the body of a class.

    from is what allows resources to be used in JS, they hide the reactivity APIs from the consumer so that the surface API is smaller. Unlike of, due to the fewer arguments required in from, though it may be more convenient to not wrap your resource abstraction in a helper function.

    import { Resource } from 'ember-resources';

    class SomeResource extends Resource {}

    class MyClass {
    data = SomeResource.from(this, () => [ ... ]);
    }

    However, if you have argument defaults or need to change the shape of arguments depending on what ergonomics you want your users to have, a wrapper function may be better.

    export function someResource(context, { foo, bar }) {
    return SomeResource.from(context, () => ... );
    }

    usage:

    import { someResource } from 'your-library';

    class SomeResource extends Resource {}

    class MyClass {
    @tracked foo;
    @tracked bar;

    data = someResource(this, {
    foo: () => this.foo,
    bar: () => this.bar
    });
    }

    Type parameters

    • Instance: Resource<ArgsWrapper, Instance>

    Parameters

    • context: object
    • Optional thunk: Thunk | (() => unknown)

    Returns Instance

Generated using TypeDoc