-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy patheval.ts
56 lines (46 loc) · 1.13 KB
/
eval.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {
DioxusChannel,
Channel,
WeakDioxusChannel,
} from "../../../document/src/ts/eval";
window.__nextChannelId = 0;
window.__channels = [];
export class WebDioxusChannel extends DioxusChannel {
js_to_rust: Channel;
rust_to_js: Channel;
owner: any;
id: number;
constructor(owner: any) {
super();
this.owner = owner;
this.js_to_rust = new Channel();
this.rust_to_js = new Channel();
this.id = window.__nextChannelId;
window.__channels[this.id] = this;
window.__nextChannelId += 1;
}
// Return a weak reference to this channel
weak(): WeakDioxusChannel {
return new WeakDioxusChannel(this);
}
// Receive message from Rust
async recv() {
return await this.rust_to_js.recv();
}
// Send message to rust.
send(data: any) {
this.js_to_rust.send(data);
}
// Send data from rust to javascript
rustSend(data: any) {
this.rust_to_js.send(data);
}
// Receive data sent from javascript in rust
async rustRecv(): Promise<any> {
return await this.js_to_rust.recv();
}
// Close the channel, dropping it.
close(): void {
window.__channels[this.id] = null;
}
}