refactor: mixin

This commit is contained in:
cha0s 2024-01-05 15:51:52 -06:00
parent 061f5e53a1
commit 37d9a22479
2 changed files with 14 additions and 8 deletions

View File

@ -19,6 +19,7 @@ import enhancedResolve from 'enhanced-resolve';
import {dump as dumpYml, load as loadYml} from 'js-yaml';
import {addHook} from 'pirates';
import compose from '../compose';
import D from '../debug';
import Flecks from '../flecks';
import R from '../require';
@ -124,13 +125,13 @@ export default class ServerFlecks extends Flecks {
const rcs = this.loadRcs(resolver);
this.installCompilers(rcs, resolver);
// Load the flecks.
const flecks = Object.fromEntries(
Object.keys(resolver)
.map((path) => [path, R(this.resolve(resolver, path))]),
);
return new ServerFlecks({
const entries = Object.keys(resolver).map((path) => [path, R(this.resolve(resolver, path))]);
// Flecks mixins.
const mixins = entries.map(([, M]) => M.hooks?.['@flecks/core.mixin']).filter((e) => e);
const Class = compose(...mixins)(ServerFlecks);
return new Class({
config,
flecks,
flecks: Object.fromEntries(entries),
platforms,
rcs,
resolver,

View File

@ -1,4 +1,4 @@
import {D, Flecks} from '@flecks/core';
import {compose, D, Flecks} from '@flecks/core';
// eslint-disable-next-line import/no-extraneous-dependencies, import/no-unresolved
const {version} = require('@flecks/web/package.json');
@ -52,7 +52,12 @@ const {version} = require('@flecks/web/package.json');
const runtime = await loader(progress.update.bind(progress));
progress.finish();
debug('starting client...');
const flecks = new Flecks(runtime);
// Flecks mixins.
const mixins = Object.entries(runtime.flecks)
.map(([, M]) => M.hooks?.['@flecks/core.mixin'])
.filter((e) => e);
const Class = compose(...mixins)(Flecks);
const flecks = new Class(runtime);
window.flecks = flecks;
try {
await Promise.all(flecks.invokeFlat('@flecks/core.starting'));