Skip to content

Revert "Revert "de-mystify resource internals""#1201

Draft
NullVoxPopuli wants to merge 2 commits into
mainfrom
revert-1199-revert-1166-make-the-return-the-value-public-api
Draft

Revert "Revert "de-mystify resource internals""#1201
NullVoxPopuli wants to merge 2 commits into
mainfrom
revert-1199-revert-1166-make-the-return-the-value-public-api

Conversation

@NullVoxPopuli

Copy link
Copy Markdown
Owner

Reverts #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>

@bolt-new-by-stackblitz

Copy link
Copy Markdown

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

@vercel

vercel Bot commented Jun 22, 2025

Copy link
Copy Markdown

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

@github-actions

github-actions Bot commented Jun 22, 2025

Copy link
Copy Markdown
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant