Skip to content

Commit

Permalink
make it clear the cache protocol type keys are just test
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvisser committed Jun 1, 2020
1 parent 0fd2f64 commit 718f1a0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ sending and receiving these messages across parent and iframe windows.
import { ProtoframeDescriptor } from 'protoframe';

const cacheProtocol: ProtoframeDescriptor<{
get: {
getFoo: {
body: { key: string };
response: { value: string };
};
set: {
setBar: {
body: { key: string; value: string };
};
}> = { type: 'cache' };
Expand Down Expand Up @@ -70,8 +70,8 @@ const data: { [key: string]: string } = {};
const cache = ProtoframePubsub.iframe(cacheProtocol);

// Implement our handlers for the ask and tell requests defined in the protocol
cache.handleTell('set', ({ key, value }) => (data[key] = value));
cache.handleAsk('get', async ({ key }) => {
cache.handleTell('setBar', ({ key, value }) => (data[key] = value));
cache.handleAsk('getFoo', async ({ key }) => {
const value = key in data ? data[key] : null;
return { value };
});
Expand All @@ -85,8 +85,8 @@ import { ProtoframePubsub } from 'protoframe';
const iframe = document.getElementById('myCacheServerIframe');
const client = ProtoframePubsub.parent(cacheProtocol, iframe);

client.tell('set', { key: 'my key', value: 'my value' });
client.tell('setBar', { key: 'my key', value: 'my value' });

// value = { value: 'my value' }
const value = await client.ask('get', { key: 'my key' });
const value = await client.ask('getFoo', { key: 'my key' });
```

0 comments on commit 718f1a0

Please sign in to comment.