From 425d2ada65f0f7cac82068580bb44c9342bf77ba Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Sat, 20 Apr 2024 07:14:17 -0700 Subject: [PATCH] Binding 'this' object to some subfunctions --- src/controllers/index.js | 7 +++++++ src/controllers/rest-api/index.js | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controllers/index.js b/src/controllers/index.js index 117de46..12f91ac 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -21,6 +21,13 @@ class Controllers { this.useCases = new UseCases({ adapters: this.adapters }) this.timerControllers = new TimerControllers({ adapters: this.adapters, useCases: this.useCases }) this.config = config + + // Bind 'this' object to all subfunction + this.initAdapters = this.initAdapters.bind(this) + this.initUseCases = this.initUseCases.bind(this) + this.attachRESTControllers = this.attachRESTControllers.bind(this) + this.attachControllers = this.attachControllers.bind(this) + this.attachRPCControllers = this.attachRPCControllers.bind(this) } // Spin up any adapter libraries that have async startup needs. diff --git a/src/controllers/rest-api/index.js b/src/controllers/rest-api/index.js index 63e18a6..c6dbf22 100644 --- a/src/controllers/rest-api/index.js +++ b/src/controllers/rest-api/index.js @@ -29,7 +29,8 @@ class RESTControllers { ) } - // console.log('Controllers localConfig: ', localConfig) + // Bind 'this' object to all subfunctions. + this.attachRESTControllers = this.attachRESTControllers.bind(this) } attachRESTControllers (app) {