Skip to content

Commit 90cde2f

Browse files
committed
chore: Add comments for JsonPayload polyfill
1 parent 914395b commit 90cde2f

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

packages/globe_runtime_ts/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ declare global {
4242
const Dart: DartGlobal;
4343

4444
const JsonPayload: {
45+
// Encoding payload using MessagePack
4546
encode(value: unknown): Uint8Array | undefined;
47+
// Decoding payload using MessagePack
4648
decode(value: Uint8Array): any;
4749
};
4850
}

src/dart_runtime.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,6 @@ import * as msgPackr from "ext:js_msg_packr/index.js";
88

99
const { core } = Deno;
1010

11-
// Expose the `JsonPayload` interface to the global scope
12-
Object.defineProperty(globalThis, "JsonPayload", {
13-
value: {
14-
encode: (value: unknown): Uint8Array | undefined => {
15-
if (value === undefined) return undefined;
16-
return msgPackr.pack(value);
17-
},
18-
decode: (value: Uint8Array | undefined): any => {
19-
if (value === undefined) return undefined;
20-
return msgPackr.unpack(value);
21-
},
22-
},
23-
enumerable: false,
24-
writable: true,
25-
configurable: true,
26-
});
27-
2811
function register_js_module(moduleName: string, moduleFunctions) {
2912
if (globalThis[moduleName]) {
3013
throw new Error(`Module "${moduleName}" is already registered.`);
@@ -81,3 +64,12 @@ register_js_module("Dart", {
8164
return _dartJSService.SendValue({ callbackId, message });
8265
},
8366
});
67+
68+
register_js_module("JsonPayload", {
69+
encode: (value: unknown): Uint8Array => {
70+
return msgPackr.pack(value);
71+
},
72+
decode: (value: Uint8Array): any => {
73+
return msgPackr.unpack(value);
74+
},
75+
});

0 commit comments

Comments
 (0)