Skip to content

Commit

Permalink
Update PM example with 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
feral-dot-io committed Nov 5, 2023
1 parent b9f1799 commit a830a2e
Show file tree
Hide file tree
Showing 10 changed files with 791 additions and 2,600 deletions.
989 changes: 615 additions & 374 deletions docs/examples/prime-ministers/assets/dioxus/dioxus-sortable.js

Large diffs are not rendered by default.

Binary file not shown.
1,090 changes: 0 additions & 1,090 deletions docs/examples/prime-ministers/assets/dioxus/dioxus.js

This file was deleted.

Binary file not shown.
1,090 changes: 0 additions & 1,090 deletions docs/examples/prime-ministers/assets/dioxus/prime-ministers.js

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,21 @@ let m,p,ls,d,t,op,i,e,z,metaflags;
node.value = value;
}
break;
case "initial_value":
node.defaultValue = value;
break;
case "checked":
node.checked = value === "true";
node.checked = truthy(value);
break;
case "selected":
node.selected = value === "true";
node.selected = truthy(value);
break;
case "dangerous_inner_html":
node.innerHTML = value;
break;
default:
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (value === "false" && bool_attrs.hasOwnProperty(name)) {
if (!truthy(value) && bool_attrs.hasOwnProperty(name)) {
node.removeAttribute(name);
} else {
node.setAttribute(name, value);
Expand Down Expand Up @@ -155,20 +158,24 @@ let m,p,ls,d,t,op,i,e,z,metaflags;
reversed: true,
selected: true,
truespeed: true,
webkitdirectory: true,
};
let u8buf,u8bufp;const evt = [];
let evt_tmp1, evt_tmp2;
function get_evt() {
evt_tmp2 = u8buf[u8bufp++];
if(evt_tmp2 & 128){
evt_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]);
evt[evt_tmp2&4294967167]=evt_tmp1;
return evt_tmp1;
function truthy(val) {
return val === "true" || val === true;
}
let s = "";let lsp,sp,sl; let c = new TextDecoder();const ns_cache = [];
let ns_cache_tmp1, ns_cache_tmp2;
function get_ns_cache() {
ns_cache_tmp2 = u8buf[u8bufp++];
if(ns_cache_tmp2 & 128){
ns_cache_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]);
ns_cache[ns_cache_tmp2&4294967167]=ns_cache_tmp1;
return ns_cache_tmp1;
}
else{
return evt[evt_tmp2&4294967167];
return ns_cache[ns_cache_tmp2&4294967167];
}
}let s,lsp,sp,sl; let c = new TextDecoder();const attr = [];
}const attr = [];
let attr_tmp1, attr_tmp2;
function get_attr() {
attr_tmp2 = u8buf[u8bufp++];
Expand All @@ -180,20 +187,20 @@ let m,p,ls,d,t,op,i,e,z,metaflags;
else{
return attr[attr_tmp2&4294967167];
}
}let u32buf,u32bufp;const ns_cache = [];
let ns_cache_tmp1, ns_cache_tmp2;
function get_ns_cache() {
ns_cache_tmp2 = u8buf[u8bufp++];
if(ns_cache_tmp2 & 128){
ns_cache_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]);
ns_cache[ns_cache_tmp2&4294967167]=ns_cache_tmp1;
return ns_cache_tmp1;
}const evt = [];
let evt_tmp1, evt_tmp2;
function get_evt() {
evt_tmp2 = u8buf[u8bufp++];
if(evt_tmp2 & 128){
evt_tmp1=s.substring(sp,sp+=u8buf[u8bufp++]);
evt[evt_tmp2&4294967167]=evt_tmp1;
return evt_tmp1;
}
else{
return ns_cache[ns_cache_tmp2&4294967167];
return evt[evt_tmp2&4294967167];
}
}
let field,id,bubbles,value,event_name,ns,ptr,len;
}let u32buf,u32bufp;let u8buf,u8bufp;
let ptr,len,ns,id,bubbles,field,value,event_name;
export function create(r){
d=r;
}
Expand All @@ -206,10 +213,7 @@ let m,p,ls,d,t,op,i,e,z,metaflags;
ls=m.getUint32(d+12*4,true);
}
p=ls;
if ((metaflags>>>5)&1){
u8buf=new Uint8Array(m.buffer,m.getUint32(d+5*4,true))
}
u8bufp=0;if (metaflags&1){
if (metaflags&1){
lsp = m.getUint32(d+1*4,true);
}
if ((metaflags>>>2)&1) {
Expand Down Expand Up @@ -238,30 +242,42 @@ let m,p,ls,d,t,op,i,e,z,metaflags;
sp=0;if ((metaflags>>>3)&1){
u32buf=new Uint32Array(m.buffer,m.getUint32(d+3*4,true))
}
u32bufp=0;
u32bufp=0;if ((metaflags>>>5)&1){
u8buf=new Uint8Array(m.buffer,m.getUint32(d+5*4,true))
}
u8bufp=0;
for(;;){
op=m.getUint32(p,true);
p+=4;
z=0;
while(z++<4){
switch(op&255){
case 0:{AppendChildren(root, stack.length-1);}break;case 1:{stack.push(nodes[u32buf[u32bufp++]]);}break;case 2:{AppendChildren(u32buf[u32bufp++], u32buf[u32bufp++]);}break;case 3:{stack.pop();}break;case 4:{root = nodes[u32buf[u32bufp++]]; els = stack.splice(stack.length-u32buf[u32bufp++]); if (root.listening) { listeners.removeAllNonBubbling(root); } root.replaceWith(...els);}break;case 5:{nodes[u32buf[u32bufp++]].after(...stack.splice(stack.length-u32buf[u32bufp++]));}break;case 6:{nodes[u32buf[u32bufp++]].before(...stack.splice(stack.length-u32buf[u32bufp++]));}break;case 7:{node = nodes[u32buf[u32bufp++]]; if (node !== undefined) { if (node.listening) { listeners.removeAllNonBubbling(node); } node.remove(); }}break;case 8:{stack.push(document.createTextNode(s.substring(sp,sp+=u32buf[u32bufp++])));}break;case 9:{node = document.createTextNode(s.substring(sp,sp+=u32buf[u32bufp++])); nodes[u32buf[u32bufp++]] = node; stack.push(node);}break;case 10:{node = document.createElement('pre'); node.hidden = true; stack.push(node); nodes[u32buf[u32bufp++]] = node;}break;case 11:event_name=get_evt();id=u32buf[u32bufp++];bubbles=u8buf[u8bufp++];node = nodes[id]; if(node.listening){node.listening += 1;}else{node.listening = 1;} node.setAttribute('data-dioxus-id', `${id}`); listeners.create(event_name, node, bubbles);break;case 12:{node = nodes[u32buf[u32bufp++]]; node.listening -= 1; node.removeAttribute('data-dioxus-id'); listeners.remove(node, get_evt(), u8buf[u8bufp++]);}break;case 13:{nodes[u32buf[u32bufp++]].textContent = s.substring(sp,sp+=u32buf[u32bufp++]);}break;case 14:{node = nodes[u32buf[u32bufp++]]; SetAttributeInner(node, get_attr(), s.substring(sp,sp+=u32buf[u32bufp++]), get_ns_cache());}break;case 15:id=u32buf[u32bufp++];field=get_attr();ns=get_ns_cache();{name = field;
node = nodes[id];
if (ns == "style") {
node.style.removeProperty(name);
} else if (ns !== null && ns !== undefined && ns !== "") {
node.removeAttributeNS(ns, name);
} else if (name === "value") {
node.value = "";
} else if (name === "checked") {
node.checked = false;
} else if (name === "selected") {
node.selected = false;
} else if (name === "dangerous_inner_html") {
node.innerHTML = "";
} else {
node.removeAttribute(name);
}}break;case 16:{nodes[u32buf[u32bufp++]] = LoadChild(u32buf[u32bufp++], u8buf[u8bufp++]);}break;case 17:ptr=u32buf[u32bufp++];len=u8buf[u8bufp++];value=s.substring(sp,sp+=u32buf[u32bufp++]);id=u32buf[u32bufp++];{
case 0:{AppendChildren(root, stack.length-1);}break;case 1:{stack.push(nodes[u32buf[u32bufp++]]);}break;case 2:{AppendChildren(u32buf[u32bufp++], u32buf[u32bufp++]);}break;case 3:{stack.pop();}break;case 4:{root = nodes[u32buf[u32bufp++]]; els = stack.splice(stack.length-u32buf[u32bufp++]); if (root.listening) { listeners.removeAllNonBubbling(root); } root.replaceWith(...els);}break;case 5:{nodes[u32buf[u32bufp++]].after(...stack.splice(stack.length-u32buf[u32bufp++]));}break;case 6:{nodes[u32buf[u32bufp++]].before(...stack.splice(stack.length-u32buf[u32bufp++]));}break;case 7:{node = nodes[u32buf[u32bufp++]]; if (node !== undefined) { if (node.listening) { listeners.removeAllNonBubbling(node); } node.remove(); }}break;case 8:{stack.push(document.createTextNode(s.substring(sp,sp+=u32buf[u32bufp++])));}break;case 9:{node = document.createTextNode(s.substring(sp,sp+=u32buf[u32bufp++])); nodes[u32buf[u32bufp++]] = node; stack.push(node);}break;case 10:{node = document.createElement('pre'); node.hidden = true; stack.push(node); nodes[u32buf[u32bufp++]] = node;}break;case 11:event_name=get_evt();id=u32buf[u32bufp++];bubbles=u8buf[u8bufp++];node = nodes[id]; if(node.listening){node.listening += 1;}else{node.listening = 1;} node.setAttribute('data-dioxus-id', `${id}`); listeners.create(event_name, node, bubbles);break;case 12:{node = nodes[u32buf[u32bufp++]]; node.listening -= 1; node.removeAttribute('data-dioxus-id'); listeners.remove(node, get_evt(), u8buf[u8bufp++]);}break;case 13:{nodes[u32buf[u32bufp++]].textContent = s.substring(sp,sp+=u32buf[u32bufp++]);}break;case 14:{node = nodes[u32buf[u32bufp++]]; SetAttributeInner(node, get_attr(), s.substring(sp,sp+=u32buf[u32bufp++]), get_ns_cache());}break;case 15:id=u32buf[u32bufp++];field=get_attr();ns=get_ns_cache();{
node = nodes[id];
if (!ns) {
switch (field) {
case "value":
node.value = "";
break;
case "checked":
node.checked = false;
break;
case "selected":
node.selected = false;
break;
case "dangerous_inner_html":
node.innerHTML = "";
break;
default:
node.removeAttribute(field);
break;
}
} else if (ns == "style") {
node.style.removeProperty(name);
} else {
node.removeAttributeNS(ns, field);
}
}break;case 16:{nodes[u32buf[u32bufp++]] = LoadChild(u32buf[u32bufp++], u8buf[u8bufp++]);}break;case 17:ptr=u32buf[u32bufp++];len=u8buf[u8bufp++];value=s.substring(sp,sp+=u32buf[u32bufp++]);id=u32buf[u32bufp++];{
node = LoadChild(ptr, len);
if (node.nodeType == Node.TEXT_NODE) {
node.textContent = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const bool_attrs = {
allowfullscreen: true,
allowpaymentrequest: true,
async: true,
autofocus: true,
autoplay: true,
checked: true,
controls: true,
default: true,
defer: true,
disabled: true,
formnovalidate: true,
hidden: true,
ismap: true,
itemscope: true,
loop: true,
multiple: true,
muted: true,
nomodule: true,
novalidate: true,
open: true,
playsinline: true,
readonly: true,
required: true,
reversed: true,
selected: true,
truespeed: true,
webkitdirectory: true,
};

export function setAttributeInner(node, field, value, ns) {
const name = field;
if (ns === "style") {
// ????? why do we need to do this
if (node.style === undefined) {
node.style = {};
}
node.style[name] = value;
} else if (ns != null && ns != undefined) {
node.setAttributeNS(ns, name, value);
} else {
switch (name) {
case "value":
if (value !== node.value) {
node.value = value;
}
break;
case "initial_value":
node.defaultValue = value;
break;
case "checked":
node.checked = truthy(value);
break;
case "selected":
node.selected = truthy(value);
break;
case "dangerous_inner_html":
node.innerHTML = value;
break;
default:
// https://github.com/facebook/react/blob/8b88ac2592c5f555f315f9440cbb665dd1e7457a/packages/react-dom/src/shared/DOMProperty.js#L352-L364
if (!truthy(value) && bool_attrs.hasOwnProperty(name)) {
node.removeAttribute(name);
} else {
node.setAttribute(name, value);
}
}
}
}

function truthy(val) {
return val === "true" || val === true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export class Dioxus {
constructor(sendCallback, returnCallback) {
this.sendCallback = sendCallback;
this.returnCallback = returnCallback;
this.promiseResolve = null;
this.received = [];
}

// Receive message from Rust
recv() {
return new Promise((resolve, _reject) => {
// If data already exists, resolve immediately
let data = this.received.shift();
if (data) {
resolve(data);
return;
}

// Otherwise set a resolve callback
this.promiseResolve = resolve;
});
}

// Send message to rust.
send(data) {
this.sendCallback(data);
}

// Internal rust send
rustSend(data) {
// If a promise is waiting for data, resolve it, and clear the resolve callback
if (this.promiseResolve) {
this.promiseResolve(data);
this.promiseResolve = null;
return;
}

// Otherwise add the data to a queue
this.received.push(data);
}
}

0 comments on commit a830a2e

Please sign in to comment.