diff --git a/tp-data.html b/tp-data.html index 1312c43..50b99fb 100644 --- a/tp-data.html +++ b/tp-data.html @@ -19,24 +19,65 @@ Tiles Protocol: Data Loading - +

Tiles Protocol: Data Loading

date2026-07-10
editorsRobin Berjon <robin@berjon.com>
issueslist, new
abstract

- XXX something about tiles protocols and how data is important + Passsing data to and from tiles is key to integrating tiles in arbitrary + environments. This protocol specifies precisely that.

Introduction

- XXX some stuff with examples about how this works + Since tiles are cut off from the network, they cannot load data for + themselves or post it to servers. This protocol enables a tile and its + hots environment to exchange data so that the tile may process or render + it and so that it can hand results back to its host.

Data Loading Protocol

- XXX readiness communication and await, then just cloning + The data protocol is loaded from /.well-known/web-tiles/data.js. + The interface exported from that has the following functions:

+ +

+ A simple example: +

+
try {
+  const { listen, addDataHandler, sendData } = await import('/.well-known/web-tiles/data.js');
+  addDataHandler((payload) => {
+    alert(`Hello ${payload.name}!`);
+    sendData({ response: 'How do you do?' });
+  });
+  listen();
+}
+catch (err) {
+  alert("Sorry, this tile can't receive data.");
+}
+      
diff --git a/tp-data.md b/tp-data.md index 9e482aa..d734cb1 100644 --- a/tp-data.md +++ b/tp-data.md @@ -1,11 +1,30 @@ # Tiles Protocol: Data Loading -XXX something about tiles protocols and how data is important +Passsing data to and from tiles is key to integrating tiles in arbitrary environments. This protocol specifies precisely that. ## Introduction -XXX some stuff with examples about how this works +Since tiles are cut off from the network, they cannot load data for themselves or post it to servers. This protocol enables a tile and its hots environment to exchange data so that the tile may process or render it and so that it can hand results back to its host. ## Data Loading Protocol -XXX readiness communication and await, then just cloning \ No newline at end of file +The data protocol is loaded from `/.well-known/web-tiles/data.js`. The interface exported from that has the following functions: + +- `addDataHandler(handler)`: sets function `handler` up to receive data sent by the host. The data is provided to the function as an object that is the structured clone of whatever the host sent. +- `removeDataHandler(handler)`: removes function `handler` from the list of functions that can receive data payloads from the host. +- `listen()`: tells the host that the tile is all set up and ready to start receiving data. This is necessary in some environments in which the host may not easily know that a tile has loaded. Always call it when ready. +- `sendData(payload)`: sends data back to the host, with `payload` being structured-cloned on the way there. + +A simple example: + +try { + const { listen, addDataHandler, sendData } = await import('/.well-known/web-tiles/data.js'); + addDataHandler((payload) => { + alert(\`Hello ${payload.name}!\`); + sendData({ response: 'How do you do?' }); + }); + listen(); +} +catch (err) { + alert("Sorry, this tile can't receive data."); +} \ No newline at end of file diff --git a/tp-data.src.html b/tp-data.src.html index 837fd87..2288c65 100644 --- a/tp-data.src.html +++ b/tp-data.src.html @@ -9,20 +9,62 @@

- XXX something about tiles protocols and how data is important + Passsing data to and from tiles is key to integrating tiles in arbitrary + environments. This protocol specifies precisely that.

Introduction

- XXX some stuff with examples about how this works + Since tiles are cut off from the network, they cannot load data for + themselves or post it to servers. This protocol enables a tile and its + hots environment to exchange data so that the tile may process or render + it and so that it can hand results back to its host.

Data Loading Protocol

- XXX readiness communication and await, then just cloning + The data protocol is loaded from /.well-known/web-tiles/data.js. + The interface exported from that has the following functions:

+ +

+ A simple example: +

+
+try {
+  const { listen, addDataHandler, sendData } = await import('/.well-known/web-tiles/data.js');
+  addDataHandler((payload) => {
+    alert(`Hello ${payload.name}!`);
+    sendData({ response: 'How do you do?' });
+  });
+  listen();
+}
+catch (err) {
+  alert("Sorry, this tile can't receive data.");
+}
+