Skip to content

Instantly share code, notes, and snippets.

@epixa
Last active August 26, 2021 10:35
Show Gist options
  • Save epixa/06c8eeabd99da3c7545ab295e49acdc3 to your computer and use it in GitHub Desktop.
Save epixa/06c8eeabd99da3c7545ab295e49acdc3 to your computer and use it in GitHub Desktop.
let internalCoreReference;
export function __initCore__(core) {
if (internalCoreReference) {
throw new Error('Core already set');
}
internalCoreReference = core;
}
export function getCore() {
if (!internalCoreReference) {
throw new Error('Core not set');
}
return internalCoreReference;
}
class Plugin {
setup(core) {
require('./core-hackery').__initCore__(core);
core.applications.register({
id: 'foo',
async mount(domElement) {
const bootstrapApp = await import('./application');
return bootstrapApp(domElement);
}
});
}
}
@mshustov
Copy link

and consumer:

// application.js
import { getCore } from './core-hackery';
const core = getCore();

@Bamieh
Copy link

Bamieh commented Jun 12, 2019

where do i put the core-hackery.js file? In public or server code?

It seems that it is on the server code. I'm confused how I can use it inside hacks code?

@epixa
Copy link
Author

epixa commented Jun 12, 2019

This example is all client-side new platform plugins. It's not directly applicable to a legacy plugin since that doesn't have a controlled lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment