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

Vote for block decorators! #340

Closed
shrinktofit opened this issue Oct 12, 2020 · 2 comments
Closed

Vote for block decorators! #340

shrinktofit opened this issue Oct 12, 2020 · 2 comments

Comments

@shrinktofit
Copy link

shrinktofit commented Oct 12, 2020

Use of legacy decorators can easily result in circular reference if a module import binding is passed to a decorator:

import Base from './base.mjs';
export default class Derived {
  @type(Base)
  base;
}
import Derived from './derived.mjs';
export default class Base {
  @type(Derived)
  derived;
}

since decorators are executed in module execution stage.

However, with block decorators, we could defer the getting of import bindings:

import Base from './base.mjs';
export default class Derived {
  @deferred(@type { Base }) // Equals to @deferred(() => Base)
                                              // We could get `Base` after all modules finished their execution!
  base;
}
@littledan
Copy link
Member

Huh, I don't see how we'd make block decorators work in an expression context like that. If we want to have deferred references, maybe this kind of decorator could help: rbuckton/proposal-refs#11

@shrinktofit
Copy link
Author

If we want to have deferred references, maybe this kind of decorator could help: rbuckton/proposal-refs#11

It does help. 👍 All I needed is just wrap the decorated expression in a function.

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

2 participants