0.0.12 • Published 2 years ago
@dstanesc/shared-tree-map v0.0.12
Shared Tree Map
Minimal Fluid SharedTree DDS instantiation for testing purposes. Includes data binding.
Install
npm install @dstanesc/shared-tree-mapUsage
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=xyzBuild & Test
Note: npm tests are pre-configured with the
fluidMode=tinysetting (seepackage.json)
npx tinyliciousnpm run clean
npm install
npm run build
npm run testLicenses
Licensed under either Apache 2.0 or MIT at your option.