API - Cloud Block
Cloud blocks represent immutable values in the database. The value cannot be changed, but a cloud block may exist in the client before the data has been loaded. Blocks may also exist in the client before they have been published to the source.
Usage
Client-side blocks should always be retrieved from a cloud doc, which in turn are retrieved by the cloud client. For example:
import createCloudClient from "@aven-cloud/cloud/createCloudClient";
const cloud = createCloudClient({ source });
const doc = cloud.get("MyDocName");
const block = doc.getBlock(); // gets the current block referenced by the doc
From a doc, there are multiple ways to access a block:
// gets the current block referenced by the doc
const block = doc.getBlock();
// gets a block from the doc, identified by id
const block = doc.getBlock('somedatachecksum');
// gets the a block with a reference object
const blockRef = { type: 'BlockReference', id: 'somedatachecksum' };
const block = doc.getBlock(blockRef);
Properties/methods
isConnected
A behavior subject of a boolean regarding the connectivity of the block. Will be true if the block's value is now available, otherwise false.
observe
A behavior subject of the block's state, including the fetch time, publish time, and currently known value.
observeValue
A behavior subject of the block's value, or undefined until the value is known.
getId
Returns the unchangable id string of this block. A checksum of the JSON data.
getValue()
Retrieve the value of the block, or `undefined` if the block hasn't been loaded yet.
async fetch()
Command a fetch of the value of the block from the source, if it has not already been fetched.
async fetchValue()
Same as `fetch()` for blocks.
async publish()
Todo! This method does not exist yet, but it should publish the doc to the source if it has not already been published.