feat: support passing Uint8Array as island props (#1225)

This commit adds support for passing Uint8Array's to islands in
component props.
This commit is contained in:
Luca Casonato
2023-05-31 08:34:57 +00:00
committed by GitHub
parent e3f9a0df08
commit 38e67b0a97
5 changed files with 72 additions and 0 deletions
+13
View File
@@ -8,6 +8,16 @@ interface Signal<T> {
value: T;
}
function b64decode(b64: string): Uint8Array {
const binString = atob(b64);
const size = binString.length;
const bytes = new Uint8Array(size);
for (let i = 0; i < size; i++) {
bytes[i] = binString.charCodeAt(i);
}
return bytes;
}
export function deserialize(
str: string,
signal?: <T>(a: T) => Signal<T>,
@@ -19,6 +29,9 @@ export function deserialize(
if (v[KEY] === "s") {
return signal!(v.v);
}
if (v[KEY] === "u8a") {
return b64decode(v.d);
}
if (v[KEY] === "l") {
const val = v.v;
val[KEY] = v.k;