Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quest: Sync with starbeam developments: (and actually get the lint implemented, since we have some footguns to protect against) #1012

Open
19 tasks
NullVoxPopuli opened this issue Oct 11, 2023 · 1 comment

Comments

@NullVoxPopuli
Copy link
Owner

NullVoxPopuli commented Oct 11, 2023

Tasks

  • on.sync

    • manages changes in consumed reactive values
    • allows cleanup behavior to occur per set of reactive changes
  • on.cleanup becomes on.finalize (but keep on.cleanup for compatibility)

  • Lints

    • finish Create eslint plugin #709
    • add
      • family of lints for inlining resource definitions within the class body
        • explore forbidding consumption of tracked args within the resource body (can lint against arg usage specifically
          • potentially auto-fixable to on.sync + return cleanup function
        • favor linting for the returned () => return value, because returning lazily accessed () => this.args.input is fine, but returning this.args.input is not.
        • prefer defining resources in module space
  • Learning materials

    • the resource body is "the constructor"-
    • on.sync allows easy managing of reactive updates, no worry about the whole thing getting torn down prematurely
    • on.finalize (formally on.cleanup) is tied to the lifetime of the parent context
    • before and after docs
      • how to be closest to starbeam
      • what was awkward before that resources make better

Notes:

resource(({ on }) => {
  evaluateCount++;
  on.sync(() => () => cleanupCount++);

  // THIS IS ILLEGAL. You can't read reactive values in the constructor
  // (because the entire would be torn down each time @input @changes)
  return this.args.input;
});

should instead be

resource(({ on }) => {
  on.sync(() => {
    syncCount++;
    return () => cleanupCount++;
  });

  return Formula(() => this.args.input);
});

however, Formula doesn't exist in ember-resources, and may not make sense today, as ember-resources already supports returning () => some value, and it's already a "cached value" (via the createCache api (which is internal in the helper managers)

@NullVoxPopuli
Copy link
Owner Author

Note: on.sync us impossfto implement in ember, pre-starbeam.

But moving the resource body into on.sync in the codemod should be safe/consistent

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

No branches or pull requests

1 participant