Skip to content

Conversation

jemmyw
Copy link
Contributor

@jemmyw jemmyw commented Oct 3, 2023

class MyController extends ApplicationController {
  initialize() {
    // Dependency callbacks can be added next to the initialization code
    document.addEventListener("keydown", handleKeyDown);
    this.addDependency(() => document.removeEventListener("keydown", handleKeyDown));

    // observe is automatically cleaned up
    this.observe(() => { console.log(this.state.someValue); });

    // Dependencies can be named so they can be trigged any time
    const connection = new Connection();
    this.addDependency("close_connection", () => connection.close());
  }

  actionClose() {
    this.resolveDependency("close_connection");
  }

  handleKeyDown = (event) => {
  }
}

@percyhanna percyhanna marked this pull request as ready for review November 16, 2023 18:50
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.

2 participants