Skip to content

Instantly share code, notes, and snippets.

@epixa

epixa/core-hackery.js Secret

Last active Jun 12, 2019
Embed
What would you like to do?
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);
}
});
}
}
@restrry

This comment has been minimized.

Copy link

@restrry restrry commented May 22, 2019

and consumer:

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

This comment has been minimized.

Copy link

@Bamieh 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

This comment has been minimized.

Copy link
Owner Author

@epixa 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