ember-resources icon indicating copy to clipboard operation
ember-resources copied to clipboard

Revert "Revert "de-mystify resource internals""

Open NullVoxPopuli opened this issue 8 months ago • 3 comments

Reverts NullVoxPopuli/ember-resources#1199

In order to merge this, we need a new test for this scenario:

export function trackedTask<
  Return = unknown,
  Args extends unknown[] = unknown[],
  LocalTask extends TaskIsh<Args, Return> = TaskIsh<Args, Return>,
>(context: object, task: LocalTask, thunk?: () => Args) {
  assert(`Task does not have a perform method. Is it actually a task?`, 'perform' in task);

  const state = new State<Args, Return, LocalTask>(task);

   
  let destroyable = resource(context, () => {
    let args = thunk || DEFAULT_THUNK;

    let positional = normalizeThunk(args).positional as Args;

    state[RUN](positional || []);

    return state;
  });

  associateDestroyableChild(destroyable, state);

  registerDestructor(state, () => state[TASK].cancelAll());
 
  /**
    This is immediately usable
  */
  return destroyable as unknown as TaskInstance<Return>;
}

Immediately usable upon access:

  output = trackedTask<string>(this, this.greeting, () => [this.args.name]);

  <template>
    <div>
      <h1>Demo Component</h1>
      <p>{{this.output.value}}</p>
    </div>
  </template>

NullVoxPopuli avatar Jun 22 '25 14:06 NullVoxPopuli

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

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ember-resources-0a9q ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 11, 2025 7:57pm

vercel[bot] avatar Jun 22 '25 14:06 vercel[bot]

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

js min min + gzip min + brotli
/index.js 14.42 kB 4.3 kB 1.74 kB 1.49 kB

github-actions[bot] avatar Jun 22 '25 14:06 github-actions[bot]