refactor: mixin
This commit is contained in:
parent
3553d6ca8d
commit
a60ac484fc
|
@ -8,9 +8,24 @@ import startFlush from './start-flush';
|
||||||
const resources = express.static(join(process.cwd(), 'projects'));
|
const resources = express.static(join(process.cwd(), 'projects'));
|
||||||
|
|
||||||
export const hooks = {
|
export const hooks = {
|
||||||
|
'@flecks/core.mixin': (Flecks) => (
|
||||||
|
class FlecksWithPerseaCore extends Flecks {
|
||||||
|
|
||||||
|
constructor(...args) {
|
||||||
|
super(...args);
|
||||||
|
if (!this.persea) {
|
||||||
|
this.persea = {};
|
||||||
|
}
|
||||||
|
if (!this.persea.core) {
|
||||||
|
this.persea.core = {};
|
||||||
|
}
|
||||||
|
this.persea.core.patches = [];
|
||||||
|
this.persea.core.replacements = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
),
|
||||||
'@flecks/core.starting': (flecks) => {
|
'@flecks/core.starting': (flecks) => {
|
||||||
flecks.set('$persea/core.patches', []);
|
|
||||||
flecks.set('$persea/core.replacements', []);
|
|
||||||
startFlush(flecks);
|
startFlush(flecks);
|
||||||
},
|
},
|
||||||
'@flecks/core.webpack': (target, config) => {
|
'@flecks/core.webpack': (target, config) => {
|
||||||
|
|
|
@ -15,13 +15,13 @@ export default (Action, flecks) => class ProjectAction extends Action {
|
||||||
const {data: {type, payload}} = packet;
|
const {data: {type, payload}} = packet;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case patchJsonResource.toString(): {
|
case patchJsonResource.toString(): {
|
||||||
flecks.get('$persea/core.patches').push(payload);
|
flecks.persea.core.patches.push(payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case redo.toString(): {
|
case redo.toString(): {
|
||||||
const {project, uri} = payload;
|
const {project, uri} = payload;
|
||||||
const path = join(process.cwd(), 'projects', project, uri);
|
const path = join(process.cwd(), 'projects', project, uri);
|
||||||
const {toBuffer, fromBuffer} = flecks.get('$avocado/resource/persea.controllers')
|
const {toBuffer, fromBuffer} = flecks.avocado.resource.persea.Controllers
|
||||||
.find(({matcher}) => uri.match(matcher));
|
.find(({matcher}) => uri.match(matcher));
|
||||||
const buffer = await readFile(path);
|
const buffer = await readFile(path);
|
||||||
const json = fromBuffer(buffer, flecks);
|
const json = fromBuffer(buffer, flecks);
|
||||||
|
@ -39,13 +39,13 @@ export default (Action, flecks) => class ProjectAction extends Action {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case replaceResource.toString(): {
|
case replaceResource.toString(): {
|
||||||
flecks.get('$persea/core.replacements').push(payload);
|
flecks.persea.core.replacements.push(payload);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case undo.toString(): {
|
case undo.toString(): {
|
||||||
const {project, uri} = payload;
|
const {project, uri} = payload;
|
||||||
const path = join(process.cwd(), 'projects', project, uri);
|
const path = join(process.cwd(), 'projects', project, uri);
|
||||||
const {toBuffer, fromBuffer} = flecks.get('$avocado/resource/persea.controllers')
|
const {toBuffer, fromBuffer} = flecks.avocado.resource.persea.Controllers
|
||||||
.find(({matcher}) => uri.match(matcher));
|
.find(({matcher}) => uri.match(matcher));
|
||||||
const buffer = await readFile(path);
|
const buffer = await readFile(path);
|
||||||
const json = fromBuffer(buffer, flecks);
|
const json = fromBuffer(buffer, flecks);
|
||||||
|
|
|
@ -5,7 +5,7 @@ import {applyPatch, compare} from 'fast-json-patch';
|
||||||
|
|
||||||
const startFlush = (flecks) => {
|
const startFlush = (flecks) => {
|
||||||
const flushPatches = async () => {
|
const flushPatches = async () => {
|
||||||
const patches = flecks.get('$persea/core.patches');
|
const {patches} = flecks.persea.core;
|
||||||
if (patches.length > 0) {
|
if (patches.length > 0) {
|
||||||
while (patches.length > 0) {
|
while (patches.length > 0) {
|
||||||
const {
|
const {
|
||||||
|
@ -16,7 +16,7 @@ const startFlush = (flecks) => {
|
||||||
} = patches.shift();
|
} = patches.shift();
|
||||||
const path = join(process.cwd(), 'projects', project, uri);
|
const path = join(process.cwd(), 'projects', project, uri);
|
||||||
// Get controller.
|
// Get controller.
|
||||||
const {toBuffer, fromBuffer} = flecks.get('$avocado/resource/persea.controllers')
|
const {toBuffer, fromBuffer} = flecks.avocado.resource.persea.Controllers
|
||||||
.find(({matcher}) => uri.match(matcher));
|
.find(({matcher}) => uri.match(matcher));
|
||||||
// Load.
|
// Load.
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
|
@ -44,7 +44,7 @@ const startFlush = (flecks) => {
|
||||||
};
|
};
|
||||||
setTimeout(flushPatches, 0);
|
setTimeout(flushPatches, 0);
|
||||||
const flushReplacements = async () => {
|
const flushReplacements = async () => {
|
||||||
const replacements = flecks.get('$persea/core.replacements');
|
const {replacements} = flecks.persea.core;
|
||||||
if (replacements.length > 0) {
|
if (replacements.length > 0) {
|
||||||
while (replacements.length > 0) {
|
while (replacements.length > 0) {
|
||||||
const {value, project, uri} = replacements.shift();
|
const {value, project, uri} = replacements.shift();
|
||||||
|
|
|
@ -92,7 +92,7 @@ function Organization({
|
||||||
nodes={nodesFromResourcePaths(label, uuid, resourcePaths)}
|
nodes={nodesFromResourcePaths(label, uuid, resourcePaths)}
|
||||||
renderLabel={({label, nodes, value}) => {
|
renderLabel={({label, nodes, value}) => {
|
||||||
const {displayName = 'Binary'} = flecks
|
const {displayName = 'Binary'} = flecks
|
||||||
.get('$avocado/resource/persea.controllers')
|
.avocado.resource.persea.Controllers
|
||||||
.find(({matcher}) => value.match(matcher))
|
.find(({matcher}) => value.match(matcher))
|
||||||
.Component;
|
.Component;
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -17,7 +17,7 @@ export const fetchProjectResource = createAsyncThunk(
|
||||||
async ({uri, uuid}, {extra: flecks}) => {
|
async ({uri, uuid}, {extra: flecks}) => {
|
||||||
Resource.root = join('/projects', uuid);
|
Resource.root = join('/projects', uuid);
|
||||||
const buffer = await Resource.read(uri);
|
const buffer = await Resource.read(uri);
|
||||||
const {fromBuffer} = flecks.get('$avocado/resource/persea.controllers')
|
const {fromBuffer} = flecks.avocado.resource.persea.Controllers
|
||||||
.find(({matcher}) => uri.match(matcher));
|
.find(({matcher}) => uri.match(matcher));
|
||||||
try {
|
try {
|
||||||
return fromBuffer(Buffer.from(buffer), flecks);
|
return fromBuffer(Buffer.from(buffer), flecks);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user