Skip to content

Commit cc5f8d5

Browse files
committed
fixed recursve loading error
1 parent 042eb68 commit cc5f8d5

File tree

3 files changed

+98
-11
lines changed

3 files changed

+98
-11
lines changed

OpenScript.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,11 +485,21 @@ var OpenScript = {
485485
* @returns
486486
*/
487487
async emit(event, ...args) {
488+
let events = event.split(/\s+/g);
489+
490+
for(let i = 0; i < events.length; i++){
491+
let evt = events[i];
492+
if(evt.length < 1) continue;
493+
this.#emit(evt, ...args);
494+
}
495+
}
496+
497+
async #emit(event, ...args){
488498
const currentTime = () => new Date().getTime();
489499

490500
this.#logs[event] = this.#logs[event] ?? [];
491501
this.#logs[event].push({ timestamp: currentTime(), args: args });
492-
if (this.#shouldLog) console.log(`fired ${event}: args`, args);
502+
if (this.#shouldLog) console.log(`fired ${event}: args: `, args);
493503

494504
return this.#emitter.emit(event, ...args);
495505
}
@@ -2858,8 +2868,10 @@ var OpenScript = {
28582868
* @param {string} fileName script name without the .js.
28592869
*/
28602870
async req(fileName) {
2861-
let names = fileName.split(/\./);
2871+
if(!/^[\w\._-]+$/.test(fileName)) throw Error(`OJS-INVALID-FILE: '${fileName}' is an invalid file name`);
28622872

2873+
let names = fileName.split(/\./);
2874+
28632875
if (OpenScript.AutoLoader.history.has(`${this.dir}.${fileName}`))
28642876
return OpenScript.AutoLoader.history.get(
28652877
`${this.dir}.${fileName}`
@@ -2870,6 +2882,7 @@ var OpenScript = {
28702882
this.version
28712883
}`
28722884
);
2885+
28732886

28742887
let classes = await response.text();
28752888
let content = classes;

example/ojs-config.js

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,29 @@
33
|----------------------------------
44
*/
55

6-
/**----------------------------------
6+
/*----------------------------------
77
*
88
* Set the default route path here
99
* ----------------------------------
1010
*/
11-
route.basePath('example'); // === '/'
11+
route.basePath(''); // === '/'
12+
13+
/*-----------------------------------
14+
| Set the global runtime prefix.
15+
| This prefix will be appended
16+
| to every path before resolution.
17+
| So ensure when defining routes,
18+
| you have it as the main prefix.
19+
|------------------------------------
20+
*/
21+
route.runtimePrefix(''); // === ''
1222

1323
/*-----------------------------------
1424
| set the directories in which we
1525
| can find the context files
1626
|-----------------------------------
1727
*/
18-
ContextProvider.directory = route.baseUrl('contexts');
28+
ContextProvider.directory = route.baseUrl('example/contexts');
1929

2030
/*-----------------------------------
2131
| set the version number of the
@@ -32,7 +42,7 @@ ContextProvider.version = '1.0.0';
3242
| from that directory
3343
|-----------------------------------
3444
*/
35-
MediatorManager.directory = route.baseUrl('mediators');
45+
MediatorManager.directory = route.baseUrl('example/mediators');
3646

3747
/*-----------------------------------
3848
| Set the version number of the
@@ -48,7 +58,7 @@ MediatorManager.version = '1.0.0';
4858
| directory for the loader
4959
|-----------------------------------
5060
*/
51-
loader.dir = route.baseUrl('components');
61+
loader.dir = route.baseUrl('example/components');
5262

5363
/*-----------------------------------
5464
| set the version number of the
@@ -65,7 +75,7 @@ loader.version = '1.0.0';
6575
|-----------------------------------
6676
*/
6777

68-
autoload.dir = route.baseUrl('classes');
78+
autoload.dir = route.baseUrl('example/classes');
6979

7080
/*-----------------------------------
7181
| set the version number of the
@@ -75,6 +85,25 @@ autoload.dir = route.baseUrl('classes');
7585
*/
7686
autoload.version = '1.0.0';
7787

88+
89+
/*---------------------------------
90+
| Get the initial body style so
91+
| so that when routes change,
92+
| we can reset the body style.
93+
| Sometimes, the body element's
94+
| style is affected by elements
95+
| That are no longer on the DOM.
96+
| example, bootstrap offcanvas.
97+
| In these cases, you need to
98+
| reset the body style when
99+
| the routeChanged event is fired
100+
| by the router. So you can listen
101+
| to it and use this to reset
102+
| the style.
103+
|----------------------------------
104+
*/
105+
var __bodyStyle = document.body.getAttribute("style");
106+
78107
/*--------------------------------
79108
| Set the logs clearing interval
80109
| for the broker to remove stale
@@ -97,4 +126,12 @@ broker.TIME_TO_GC = 10000; // 10 secs
97126
| collector for the broker
98127
|-------------------------------------------
99128
*/
100-
broker.removeStaleEvents(); // broker garbage collection started
129+
broker.removeStaleEvents(); // broker garbage collection started
130+
131+
/*------------------------------------------
132+
| When this is set to true, the broker
133+
| will display events and their payloads
134+
| in the console when they are fired
135+
|------------------------------------------
136+
*/
137+
broker.withLogs(true);

ojs-config.js

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,23 @@
33
|----------------------------------
44
*/
55

6-
/**----------------------------------
6+
/*----------------------------------
77
*
88
* Set the default route path here
99
* ----------------------------------
1010
*/
1111
route.basePath(''); // === '/'
1212

13+
/*-----------------------------------
14+
| Set the global runtime prefix.
15+
| This prefix will be appended
16+
| to every path before resolution.
17+
| So ensure when defining routes,
18+
| you have it as the main prefix.
19+
|------------------------------------
20+
*/
21+
route.runtimePrefix(''); // === ''
22+
1323
/*-----------------------------------
1424
| set the directories in which we
1525
| can find the context files
@@ -75,6 +85,25 @@ autoload.dir = route.baseUrl('js/classes');
7585
*/
7686
autoload.version = '1.0.0';
7787

88+
89+
/*---------------------------------
90+
| Get the initial body style so
91+
| so that when routes change,
92+
| we can reset the body style.
93+
| Sometimes, the body element's
94+
| style is affected by elements
95+
| That are no longer on the DOM.
96+
| example, bootstrap offcanvas.
97+
| In these cases, you need to
98+
| reset the body style when
99+
| the routeChanged event is fired
100+
| by the router. So you can listen
101+
| to it and use this to reset
102+
| the style.
103+
|----------------------------------
104+
*/
105+
var __bodyStyle = document.body.getAttribute("style");
106+
78107
/*--------------------------------
79108
| Set the logs clearing interval
80109
| for the broker to remove stale
@@ -97,4 +126,12 @@ broker.TIME_TO_GC = 10000; // 10 secs
97126
| collector for the broker
98127
|-------------------------------------------
99128
*/
100-
broker.removeStaleEvents(); // broker garbage collection started
129+
broker.removeStaleEvents(); // broker garbage collection started
130+
131+
/*------------------------------------------
132+
| When this is set to true, the broker
133+
| will display events and their payloads
134+
| in the console when they are fired
135+
|------------------------------------------
136+
*/
137+
broker.withLogs(true);

0 commit comments

Comments
 (0)