Skip to content

Commit 5013337

Browse files
committed
Refactor and optimize script loading
Closes: #158 PR-URL: #160
1 parent 828c33c commit 5013337

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

lib/application.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Application extends events.EventEmitter {
6161
}
6262
}
6363

64-
runScript(methodName, session) {
64+
runMethod(methodName, session) {
6565
const script = this.api.get(methodName);
6666
if (!script) return null;
6767
const exp = script(session ? session.context : EMPTY_CONTEXT);
@@ -103,15 +103,16 @@ class Application extends events.EventEmitter {
103103

104104
async loadPlace(place, placePath) {
105105
const files = await fsp.readdir(placePath, { withFileTypes: true });
106+
const isStatic = place === 'static';
106107
for (const file of files) {
107108
const filePath = path.join(placePath, file.name);
108-
if (place !== 'static') await this.loadScript(place, filePath);
109+
if (!isStatic) await this.loadScript(place, filePath);
109110
else if (file.isDirectory()) await this.loadPlace(place, filePath);
110111
else await this.loadFile(filePath);
111112
}
112113
fs.watch(placePath, (event, fileName) => {
113114
const filePath = path.join(placePath, fileName);
114-
if (place === 'static') this.loadFile(filePath);
115+
if (isStatic) this.loadFile(filePath);
115116
else this.loadScript(place, filePath);
116117
});
117118
}

lib/client.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Client {
7777
}
7878
try {
7979
const session = await application.auth.restore(this);
80-
const proc = application.runScript(method, session);
80+
const proc = application.runMethod(method, session);
8181
if (!proc) {
8282
this.error(404);
8383
return;

0 commit comments

Comments
 (0)