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

Dependency annotations #2

Open
L8D opened this issue Dec 21, 2015 · 0 comments
Open

Dependency annotations #2

L8D opened this issue Dec 21, 2015 · 0 comments
Labels

Comments

@L8D
Copy link
Member

L8D commented Dec 21, 2015

After we get a system in place to handle them properly, there is a plan to create annotations and annotation handlers for the following:

  • A token for representing the instance of the dependency that the current dependency is providing. Example:
@provide(DbConn)
@dependencies(Super)
class TransactionalDbConn {
  constructor(originalDbConn) {
    return originalDbConn.byTransaction();
  }
}
  • An annotation for injecting a dependency lazily (i.e. a prototype of the constructor is passed in, before the constructor is applied to the prototype). This would allow for systems for more efficiently initialize because resources can be referenced and inserted while they are still loading. Although error handling and other problems arise. Example:
@dependencies(Lazy(CurrentUser))
class CurrentOrder {
  constructor(user) {
    return new Order({user, /* ... */});
  }
}
  • An annotation for injecting the promise of a dependency. This would be a more robust but less fancy form of lazy loading, where the promise of a resource that is resolving is passed in, instead of waiting for the promise to resolve and then passing in the result. This would be mostly used for handling parallelization in a form better than lazy loading or for handling errors that would be thrown during instantiation (although there should be an annotation specifically for that). Example:
@dependencies(Async(CurrentUser))
class CurrentOrder {
  constructor(userPromise) {
    return Promise.props({
      order: something.getCurrentOrder(),
      user: userPromise
    }).then({order, user} => {user, ...order});
}
  • An annotation (or maybe an alternative @provide-like decorator) for allowing thrown errors to be caught and handled. Although this could probably be replaced by making the Super token wrap the mocked resource.
@L8D L8D added feature and removed enhancement labels Feb 6, 2016
@L8D L8D changed the title Lazy loading and other dependency types Dependency annotations Feb 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant