Skip to content

Commit

Permalink
modernized eel.js's for loops and a few other things
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume-mueller committed Jan 28, 2025
1 parent 6a29024 commit a53b8f6
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions eel/eel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class Eel {
#mock_queue = [];

#mock_py_functions() {
for (let i = 0; i < this.#py_functions.length; i++) {
const name = this.#py_functions[i];
for (let name of this.#py_functions)
this[name] = function() {
const call_object = this.#call_object(name, arguments);
this.#mock_queue.push(call_object);
return this.#call_return(call_object);
}
}
};
}

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

#call_return_callbacks = {};

#call_object(name, args) {
const arg_array = [];
for (let i = 0; i < args.length; i++)
arg_array.push(args[i]);
const call_id = (this.#call_number += 1) + Math.random();
return {'call': call_id, 'name': name, 'args': arg_array};
}
#call_object = (name, args) => ({
'call': (this.#call_number += 1) + Math.random(),
'name': name,
'args': [...args]
});

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

this.#websocket.onopen = () => {
for (let i = 0; i < this.#py_functions.length; i++) {
const py_function = this.#py_functions[i];
this.#import_py_function(py_function);
}
for (let func_name of this.#py_functions)
this.#import_py_function(func_name);
while (this.#mock_queue.length > 0) {
const call = this.#mock_queue.shift();
this.#websocket.send(this.#to_json(call));
Expand Down

0 comments on commit a53b8f6

Please sign in to comment.