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

provide "dependency fulfilled" life cycle in order to avoid NPE on constructor #8

Closed
k1r0s opened this issue Mar 25, 2020 · 0 comments

Comments

@k1r0s
Copy link
Owner

k1r0s commented Mar 25, 2020

sample issue:

import { Provider, Dependency } from "@ritley/decorators";
import { OpcuaService } from "../services/opcua.service";
import { ConfigService } from "../services/config.service";

export { ApiModule }

@Provider.factory
@Dependency("client", OpcuaService)
@Dependency("config", ConfigService)
class ApiModule {

  values = null;

  // FIXME: ritley (lib) should provide "dependency fulfilled" life cycle in order to avoid this:
  constructor() {
    setTimeout(() => this.initialize(), 10);
  }

  initialize() {
    this.config.getContents().then(values => {
      this.values = values;
      this.start(this.values.address);
    })
  }

  async start(address) {
    await this.client.doConnect(address);
    await this.client.createSession();
  }

  browse(nodeId) {
    return this.client.browseChilds(nodeId || this.values.rootNode);
  }
}
@k1r0s k1r0s closed this as completed in 5e4f002 Mar 26, 2020
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