Quick Start
Let’s start using Yorkie with JS SDK and Server. You need an environment that can run JavaScript, such as a browser.
Installation
Install Yorkie JS SDK using npm:
$ npm install yorkie-js-sdk
or just include the following code in the <head>
tag of your HTML:
<!-- include yorkie js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/yorkie-js-sdk/0.2.4/yorkie-js-sdk.js"></script>
If you want to test Yorkie quickly, You can start Envoy
and Yorkie
with docker-compose
. To start them, downloads manifests files from docker folder, then type docker-compose up --build -d
in the folder.
For more details please refer to Server for Web
How to use
1. Activating Client
First, create client with RPCAddr then activate it.
const client = yorkie.createClient('localhost:8080');
await client.activate();
2. Attaching Document
Then create a document with a key of document then attach it into the client.
const doc = yorkie.createDocument('doc-1');
await client.attach(doc);
This automatically synchronizes all changes to the document attached to the client with the remote peers.
3. Updating Document
Now let’s make a change on the document:
doc.update((root) => {
root['key'] = 'value'; // {"key":"value"}
});
The changes are applied immediately locally and propagated to other peers that have attached the document.
Next, let’s take a look at the JS SDK.