@dstanesc/shared-tree-map
TypeScript icon, indicating that this package has built-in type declarations

0.0.12 • Public • Published

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

Hello World

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 (see package.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.

Readme

Keywords

none

Package Sidebar

Install

npm i @dstanesc/shared-tree-map

Weekly Downloads

0

Version

0.0.12

License

MIT

Unpacked Size

99.7 kB

Total Files

30

Last publish

Collaborators

  • dstanesc