Skip to content

Commit

Permalink
Update EXPLAINER.md
Browse files Browse the repository at this point in the history
Make it explicit that file references can not only be serialized, but also postMessaged.

Fixes #7
  • Loading branch information
mkruisselbrink committed Aug 1, 2018
1 parent 6b552a2 commit bd28fc8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions EXPLAINER.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 108,24 @@ request.onsuccess = function(e) {
}
```

The fact that handles are serializable also means you can `postMessage` them around:

```javascript
// In a service worker:
self.addEventListener('some-hypothetical-launch-event', e => {
// e.file is a FileSystemFileHandle representing the file this SW was launched with.
let win = await clients.openWindow('bla.html');
if (win)
win.postMessage({openFile: e.file});
});

// In bla.html
navigator.serviceWorker.addEventListener('message', e => {
let file_ref = e.openFile;
// Do something useful with the file reference.
});
```

Also possible to get access to an entire directory.

```javascript
Expand Down

0 comments on commit bd28fc8

Please sign in to comment.