-
Notifications
You must be signed in to change notification settings - Fork 0
Programmatic Usage (Advanced)
While the default project does a lot of heavy lifting, PatchBay can be used programmatically with just a few things to keep in mind to avoid unexpected or undefined behavior.
The global PatchBay
will always be set to the latest-created instance of PBApp. This is why launch.ts
in the
default project doesn't bother assigning the PBApp
to anything. However, the constructor does return the instance,
so you can assign it to be used programmatically if you want multiple PBApp
instances running. Just remember to avoid
using the global PatchBay
, or you may get some unexpected behavior.
Some internals rely on the global PatchBay
, but there's an easy way to override it in all circumstances:
/* Use of PBRequest is an edge case itself, let alone in programmatic usage,
but it is possible to manually set the PBAPP instance of a PBRequest when
creating one (beginning in 0.1.6)*/
PBRequest.ify(req, {
app: customPBAppInstance
})
PBUtils.TemplateResponse("my-template", {data: "data"}, {
/* Pass in a template record like below to override
the use of the global one */
templates: customPBInstance.templates
});
Unless you have a views folder in the root directory you'd like to use, you should disable the automatic loading of Handlebars templates to avoid an error on launch. See advanced usage in templates for details.