Context

colab change context

interface Context {
    counter(key: string) : Counter;;
    getTreeContext(): any;;
    text(key: string) : Text;;
    tree(): Tree;;
}

index

Methods

counter

counter(key: string) : Counter;

get counter for counter specific ops

let ctx: Context = colab.getChangeContext();
ctx.counter('clicks').inc() // increment

Parameters

key

counter key

string
Returns

Counter

Counter

getTreeContext

getTreeContext(): any;

similar to tree(), gives a straight forward approach in changing state

useful for type checking the state

NOTE that although the changes look like javascript array or object changes, they are not. as only a subset of operations are supported.

arrays

insert(index, value)

push()

pop()

all objects and values

update(value)

delete()

value()

let ctx: Context = colab.getChangeContext();
let state: {tasks : Task[]} = ctx.getTreeContext();
// insert in list
state.tasks.insert(0, {title: 'task 1', description: 'task'})
// update directly
state.tasks[0].title = "updated title"
Returns
any

text

text(key: string) : Text;

get text for text specific operations

let ctx: Context = colab.getChangeContext();
// insert
ctx.text('doc).insert(0,'hello world');
// delete 'hello'
ctx.text('doc).delete(0,5);

Parameters

key

text key

string
Returns

Text

Text

tree

tree(): Tree;

get colab tree for tree operations

let ctx: Context = colab.getChangeContext();
ctx.tree()
 .path(['tasks'])
 .list()
 .insert(0, {title: 'task 1', description: 'task'})
// this is similar to
let ctx: Context = colab.getChangeContext();
let state: {tasks : Task[]} = ctx.getTreeContext();
state.tasks.insert(0, {title: 'task 1', description: 'task'})
Returns

Tree

Tree