@dstanesc/shared-tree-map
v0.0.12
Published
Simple alpha shared tree instantiation for testing
Downloads
15
Readme
Shared Tree Map
Minimal Fluid SharedTree DDS instantiation for testing purposes. Includes data binding.
Install
npm install @dstanesc/shared-tree-map
Usage
Author data
import { initMap } from "@dstanesc/shared-tree-map";
const sharedMap = await initMap(mapId, "tiny");
sharedMap.set("key1", "abc");
sharedMap.set("key2", "def");
sharedMap.delete("key1");
Subscribe to changes using the invalidation binder
import { initMap } from "@dstanesc/shared-tree-map";
const sharedMap = await initMap(mapId, "tiny");
const binder = sharedMap.getInvalidationBinder();
binder.bindOnInvalid(() => {
updateLocalModel(sharedMap.asMap());
});
Subscribe to changes using the direct binder. It is unsafe to read the shared map directly from the callback. It is recommended to use the buffering binder instead.
const binder = sharedMap.getDirectBinder();
binder.bindOnChange(
(key: string, value: string) => {
localModel.set(key, value);
},
(key: string) => {
localModel.delete(key);
}
);
Subscribe to changes using the buffering binder
const binder = sharedMap.getBufferingBinder();
binder.bindOnChange(
(key: string, value: string) => {
localModel.set(key, value);
},
(key: string) => {
localModel.delete(key);
}
);
Subscribe to changes using the batching binder
const binder = sharedMap.getBatchingBinder();
binder.bindOnBatch((batch: MapOperation[]) => {
for (const op of batch) {
if (op.type === "insert") {
localModel.set(op.key, op.value);
} else if (op.type === "delete") {
localModel.delete(op.key);
}
}
});
Used By
Configure Fluid Service
If using frs
fluidMode, set-up both SECRET_FLUID_TENANT
and SECRET_FLUID_TOKEN
env. vars. (as configured in your azure service - Tenant Id
respectively Primary key
)
Example
SECRET_FLUID_TOKEN=xyz
SECRET_FLUID_TENANT=xyz
Build & Test
Note: npm tests are pre-configured with the
fluidMode=tiny
setting (seepackage.json
)
npx tinylicious
npm run clean
npm install
npm run build
npm run test
Licenses
Licensed under either Apache 2.0 or MIT at your option.