Skip to content

Commit

Permalink
✨ Add Conduit#getController(controller_name) to get/create a contro…
Browse files Browse the repository at this point in the history
…ller instance
  • Loading branch information
skerit committed Oct 5, 2023
1 parent abe1f2c commit 386fbfa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Don't log `.js.map` 404 errors
* Add `Conduit.Socket#is_connected` property
* Add checksum support to the `ObjectId` class
* Add `Conduit#getController(controller_name)` to get/create a controller instance

## 1.3.15 (2023-07-03)

Expand Down
28 changes: 28 additions & 0 deletions lib/class/conduit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,34 @@ Conduit.setMethod(function getSession(allow_create = true) {
return session;
});

/**
* Create a controller of the given type and attach this conduit
*
* @author Jelle De Loecker <jelle@elevenways.be>
* @since 1.3.16
* @version 1.3.16
*
* @param {String} controller_name
*
* @return {Controller}
*/
Conduit.setMethod(function getController(controller_name) {

if (!controller_name) {
return this.controller;
}

let instance = Controller.get(controller_name);

if (!instance) {
return false;
}

instance.conduit = this;

return instance;
});

/**
* Register live data bindings via websockets
*
Expand Down

0 comments on commit 386fbfa

Please sign in to comment.