diff --git a/packages/core/src/server/index.js b/packages/core/src/server/index.js index 8a19cf7..65c90a2 100644 --- a/packages/core/src/server/index.js +++ b/packages/core/src/server/index.js @@ -8,9 +8,24 @@ import startFlush from './start-flush'; const resources = express.static(join(process.cwd(), 'projects')); 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.set('$persea/core.patches', []); - flecks.set('$persea/core.replacements', []); startFlush(flecks); }, '@flecks/core.webpack': (target, config) => { diff --git a/packages/core/src/server/packets/decorators/action.js b/packages/core/src/server/packets/decorators/action.js index 2e2a0d3..b922325 100644 --- a/packages/core/src/server/packets/decorators/action.js +++ b/packages/core/src/server/packets/decorators/action.js @@ -15,13 +15,13 @@ export default (Action, flecks) => class ProjectAction extends Action { const {data: {type, payload}} = packet; switch (type) { case patchJsonResource.toString(): { - flecks.get('$persea/core.patches').push(payload); + flecks.persea.core.patches.push(payload); break; } case redo.toString(): { const {project, uri} = payload; 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)); const buffer = await readFile(path); const json = fromBuffer(buffer, flecks); @@ -39,13 +39,13 @@ export default (Action, flecks) => class ProjectAction extends Action { break; } case replaceResource.toString(): { - flecks.get('$persea/core.replacements').push(payload); + flecks.persea.core.replacements.push(payload); break; } case undo.toString(): { const {project, uri} = payload; 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)); const buffer = await readFile(path); const json = fromBuffer(buffer, flecks); diff --git a/packages/core/src/server/start-flush.js b/packages/core/src/server/start-flush.js index 9fb212e..36ba089 100644 --- a/packages/core/src/server/start-flush.js +++ b/packages/core/src/server/start-flush.js @@ -5,7 +5,7 @@ import {applyPatch, compare} from 'fast-json-patch'; const startFlush = (flecks) => { const flushPatches = async () => { - const patches = flecks.get('$persea/core.patches'); + const {patches} = flecks.persea.core; if (patches.length > 0) { while (patches.length > 0) { const { @@ -16,7 +16,7 @@ const startFlush = (flecks) => { } = patches.shift(); const path = join(process.cwd(), 'projects', project, uri); // Get controller. - const {toBuffer, fromBuffer} = flecks.get('$avocado/resource/persea.controllers') + const {toBuffer, fromBuffer} = flecks.avocado.resource.persea.Controllers .find(({matcher}) => uri.match(matcher)); // Load. // eslint-disable-next-line no-await-in-loop @@ -44,7 +44,7 @@ const startFlush = (flecks) => { }; setTimeout(flushPatches, 0); const flushReplacements = async () => { - const replacements = flecks.get('$persea/core.replacements'); + const {replacements} = flecks.persea.core; if (replacements.length > 0) { while (replacements.length > 0) { const {value, project, uri} = replacements.shift(); diff --git a/packages/core/src/sidebar/organization/organization/index.jsx b/packages/core/src/sidebar/organization/organization/index.jsx index 229ecf6..f71fb53 100644 --- a/packages/core/src/sidebar/organization/organization/index.jsx +++ b/packages/core/src/sidebar/organization/organization/index.jsx @@ -92,7 +92,7 @@ function Organization({ nodes={nodesFromResourcePaths(label, uuid, resourcePaths)} renderLabel={({label, nodes, value}) => { const {displayName = 'Binary'} = flecks - .get('$avocado/resource/persea.controllers') + .avocado.resource.persea.Controllers .find(({matcher}) => value.match(matcher)) .Component; return ( diff --git a/packages/core/src/state/projects.js b/packages/core/src/state/projects.js index c0f00c6..5f908ce 100644 --- a/packages/core/src/state/projects.js +++ b/packages/core/src/state/projects.js @@ -17,7 +17,7 @@ export const fetchProjectResource = createAsyncThunk( async ({uri, uuid}, {extra: flecks}) => { Resource.root = join('/projects', uuid); 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)); try { return fromBuffer(Buffer.from(buffer), flecks);