This commit is contained in:
Miles Murgaw authored and GitHub committed 2025-04-15 14:20:25 -07:00
1 parent a1107de0c0
commit 9ffa42392f
10 files changed
+31 -6

No files matched your search

+2
View File
@@ -136,6 +136,8 @@ impl Document for WebDocument {
const PROMISE_WRAPPER: &str = r#"
return (async function(){
{JS_CODE}
dioxus.close();
})();
"#;
+1 -1
View File
@@ -1 +1 @@
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}class WebDioxusChannel extends DioxusChannel{js_to_rust;rust_to_js;owner;constructor(owner){super();this.owner=owner,this.js_to_rust=new Channel,this.rust_to_js=new Channel}weak(){return new WeakDioxusChannel(this)}async recv(){return await this.rust_to_js.recv()}send(data){this.js_to_rust.send(data)}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){return await this.js_to_rust.recv()}}export{WebDioxusChannel};
class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}window.__nextChannelId=0;window.__channels=[];class WebDioxusChannel extends DioxusChannel{js_to_rust;rust_to_js;owner;id;constructor(owner){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}weak(){return new WeakDioxusChannel(this)}async recv(){return await this.rust_to_js.recv()}send(data){this.js_to_rust.send(data)}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){return await this.js_to_rust.recv()}close(){window.__channels[this.id]=null}}export{WebDioxusChannel};
+1 -1
View File
@@ -1 +1 @@
[1614426347475783279]
[857504888396904142]
+13
View File
@@ -4,16 +4,24 @@ import {
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
@@ -40,4 +48,9 @@ export class WebDioxusChannel extends DioxusChannel {
async rustRecv(): Promise<any> {
return await this.js_to_rust.recv();
}
// Close the channel, dropping it.
close(): void {
window.__channels[this.id] = null;
}
}