sharedb-jsproxy
Version:
ShareDB JS Proxy
33 lines (21 loc) • 917 B
Markdown
[](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) to [ShareDB](https://github.com/share/sharedb) document.
Setting a value on this proxy will update the document on the backend.
Getting a value from this proxy reflects the document on the backend.
```
const shareDbJSProxy = new ShareDBJSProxy(shareDbDoc);
const oldValue = await shareDbJSProxy.key; // await for get operation to complete
shareDbJSProxy.key = "value";
await shareDbJSProxy.key; // await for set operation to complete
const newValue = await shareDbJSProxy.key; // await for get operation to complete
console.log({ oldValue, newValue });
```
```
const shareDbJSProxy = new ShareDBJSProxy(shareDbDoc);
shareDbJSProxy.__proxy__.on('change', event => {
debug("ShareDBJSProxy event", event);
});
```