Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit 6df9b60

Browse files
modernized eel.js's for loops and a few other things
1 parent abc2c94 commit 6df9b60

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

eel/eel.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,12 @@ class Eel {
3131
#mock_queue = [];
3232

3333
#mock_py_functions() {
34-
for (let i = 0; i < this.#py_functions.length; i++) {
35-
const name = this.#py_functions[i];
34+
for (let name of this.#py_functions)
3635
this[name] = function() {
3736
const call_object = this.#call_object(name, arguments);
3837
this.#mock_queue.push(call_object);
3938
return this.#call_return(call_object);
40-
}
41-
}
39+
};
4240
}
4341

4442
#import_py_function(name) {
@@ -53,13 +51,11 @@ class Eel {
5351

5452
#call_return_callbacks = {};
5553

56-
#call_object(name, args) {
57-
const arg_array = [];
58-
for (let i = 0; i < args.length; i++)
59-
arg_array.push(args[i]);
60-
const call_id = (this.#call_number += 1) + Math.random();
61-
return {'call': call_id, 'name': name, 'args': arg_array};
62-
}
54+
#call_object = (name, args) => ({
55+
'call': (this.#call_number += 1) + Math.random(),
56+
'name': name,
57+
'args': [...args]
58+
});
6359

6460
#sleep(ms) {
6561
return new Promise(resolve => setTimeout(resolve, ms));
@@ -109,10 +105,8 @@ class Eel {
109105
this.#websocket = new WebSocket(websocket_addr);
110106

111107
this.#websocket.onopen = () => {
112-
for (let i = 0; i < this.#py_functions.length; i++) {
113-
const py_function = this.#py_functions[i];
114-
this.#import_py_function(py_function);
115-
}
108+
for (let func_name of this.#py_functions)
109+
this.#import_py_function(func_name);
116110
while (this.#mock_queue.length > 0) {
117111
const call = this.#mock_queue.shift();
118112
this.#websocket.send(this.#to_json(call));

0 commit comments

Comments
 (0)