Skip to content

Commit

Permalink
Expose state classes through GlobalApi
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsOnlyBinary committed Feb 7, 2024
1 parent 3e95a17 commit a83414e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
13 changes: 8 additions & 5 deletions build/webpack/exports-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ function accesorString(value) {
let propertyString = entry;
let result = '';

for (let i = 0; i < childProperties.length; i++) {
for (let i = 0; i <= childProperties.length; i++) {
if (i > 0) result += `if(!${propertyString}) ${propertyString} = {};\n`;
propertyString += `[${JSON.stringify(childProperties[i])}]`;
if (i === childProperties.length) {
propertyString += '["##root"]';
} else {
propertyString += `[${JSON.stringify(childProperties[i])}]`;
}
}

result += `${propertyString}`;
Expand All @@ -27,10 +31,9 @@ module.exports = function(source) {
let a = '\r\n';
a += `${entry} = ${entry} || {};\r\n`;
a += accesorString(resource);
a += `\r\n${entry}.${resource} = exports.default ? exports.default : exports;\r\n`;

a += ' = exports.default ? exports.default : exports;\r\n';
source += a;
}

return source;
};
};
4 changes: 2 additions & 2 deletions src/libs/GlobalApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class GlobalApi extends EventEmitter {
*/
require(modPath) {
let path = modPath.replace(/\//g, '.');
let mod = _.get(this.exports, path);
let mod = _.get(this.exports, path + '.##root');
if (typeof mod === 'undefined') {
Logger.error('Module does not exist: ' + modPath);
}
Expand Down Expand Up @@ -284,7 +284,7 @@ export default class GlobalApi extends EventEmitter {
* @param {Object} source The new module to insert in place
*/
replaceModule(dest, source) {
let mod = this.require(dest);
let mod = this.require(dest + '##root');
if (!mod) {
throw new Error(`The module ${dest} does not exist`);
}
Expand Down
2 changes: 2 additions & 0 deletions src/libs/state/BufferState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @module */

'kiwi public';

import Vue from 'vue';
import _ from 'lodash';
import { def } from './common';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/state/NetworkState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @module */

'kiwi public';

import Vue from 'vue';
import { def } from './common';
import * as IrcClient from '../IrcClient';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/state/UserState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/** @module */

'kiwi public';

import Vue from 'vue';
import getState from '@/libs/state';
import * as TextFormatting from '@/helpers/TextFormatting';
Expand Down

0 comments on commit a83414e

Please sign in to comment.