flecks/packages/core/build/flecks.hooks.js

129 lines
3.3 KiB
JavaScript
Raw Normal View History

2024-01-23 09:06:00 -06:00
export const hooks = {
/**
* Babel configuration.
2024-01-29 08:15:22 -06:00
* @invoke SequentialAsync
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.babel': () => ({
plugins: ['...'],
}),
/**
2024-01-27 12:55:29 -06:00
* Define configuration. See [the configuration page](./config) for more details.
2024-01-29 08:15:22 -06:00
* @invoke Fleck
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.config': () => ({
whatever: 'configuration',
your: 1337,
fleck: 'needs',
/**
* Also, comments like this will be used to automatically generate documentation.
*/
though: 'you should keep the values serializable',
}),
2024-01-29 02:41:55 -06:00
/**
* Let flecks gather for you.
*
* See [the Gathering guide](../gathering).
2024-01-29 08:15:22 -06:00
* @invoke Async
2024-01-29 02:41:55 -06:00
*/
'@flecks/core.gathered': () => ({
// If this hook is implemented by a fleck called `@some/fleck`, then:
//
// This is equivalent to flecks.gather('@some/fleck.somethings'):
somethings: {},
//
// This is equivalent to flecks.gather('@some/fleck.others', {typeProperty: 'name'}):
others: {
typeProperty: 'name',
},
}),
2024-01-23 09:06:00 -06:00
/**
2024-02-06 08:16:53 -06:00
* Invoked when a module is HMR'd. Throw to abort hot reload and restart application.
* Must be synchronous.
*
2024-01-23 09:06:00 -06:00
* @param {string} path The path of the fleck
2024-02-06 08:16:53 -06:00
* @param {Module} updated The updated module.
* @invokeSequential
2024-01-23 09:06:00 -06:00
*/
2024-02-06 08:16:53 -06:00
'@flecks/core.hmr': (path, updated) => {
2024-01-23 09:06:00 -06:00
if ('my-fleck' === path) {
2024-02-06 08:16:53 -06:00
updated.doSomething();
2024-01-23 09:06:00 -06:00
}
},
/**
* Invoked when a gathered set is HMR'd.
* @param {constructor} gathered The gathered set.
2024-01-28 12:27:13 -06:00
* @param {string} hook The gather hook; e.g. `@flecks/db.models`.
2024-01-29 08:15:22 -06:00
* @invoke
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.hmr.gathered': (gathered, hook) => {
// Do something with the gathered set...
},
/**
* Invoked when a gathered class is HMR'd.
* @param {constructor} Class The class.
2024-01-28 12:27:13 -06:00
* @param {string} hook The gather hook; e.g. `@flecks/db.models`.
2024-01-29 08:15:22 -06:00
* @invoke
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.hmr.gathered.class': (Class, hook) => {
// Do something with Class...
},
/**
* Invoked when flecks is building a fleck dependency graph.
* @param {Digraph} graph The dependency graph.
2024-01-28 12:27:13 -06:00
* @param {string} hook The hook; e.g. `@flecks/server.up`.
2024-01-29 08:15:22 -06:00
* @invoke
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.priority': (graph, hook) => {
// Make `@flecks/socket/server`'s `@flecks/server.up` implementation depend on
// `@flecks/db/server`'s:
if ('@flecks/server.up' === hook) {
graph.addDependency('@flecks/socket/server', '@flecks/db/server');
// Remove a dependency.
graph.removeDependency('@flecks/socket/server', '@flecks/db/server');
}
},
2024-01-27 08:10:21 -06:00
/**
* Invoked when a fleck is registered.
* @param {string} fleck
* @param {Module} M
2024-01-29 08:15:22 -06:00
* @invoke
2024-01-27 08:10:21 -06:00
*/
'@flecks/core.registered': (fleck, M) => {
if ('@something/or-other' === fleck) {
doSomethingWith(M);
}
},
2024-02-07 10:15:07 -06:00
/**
* Invoked when `flecks.yml` is hot reloaded. Throw to abort hot reload and restart application.
* Must be synchronous.
*
* @param {string} fleck The fleck whose config changed.
* @param {Object} config The new config.
*/
'@flecks/core.reload': (fleck, config, flecks) => {
if ('i-care-about' === fleck) {
if (flecks.get(`${fleck}.volatile`) !== config.volatile) {
throw new Error('Changes too volatile');
}
}
2024-02-08 03:18:26 -06:00
},
2024-02-07 10:15:07 -06:00
2024-01-23 09:06:00 -06:00
/**
2024-01-29 02:41:55 -06:00
* Invoked when the application is starting.
2024-01-29 08:15:22 -06:00
* @invoke SequentialAsync
2024-01-23 09:06:00 -06:00
*/
'@flecks/core.starting': () => {
console.log('starting!');
},
};