Documentation ¶
Overview ¶
Package types implements OT-compatible immutable values.
Strings are implemented by S8 and S16. S8 implements the standard Go string where offsets refer to bytes. S16 is a better choice for working with UFT16 encoded values such as is native to Javascript. In this case, the offsets count the number of UF16 units (which maps to native JS string offsets).
General arrays values can be represented by A while M implements maps.
Counter implements a 32-bit integer counter. This also serves as an example of an interesting data structure as it uses a virtual array as far as OT is concerned but only stores the accumuated count.
A much richer type is available at https://godoc.org/github.com/dotchain/dot/x/rt which also demonstrates how to implement a custom change that is applicable to the type.
Index ¶
- type A
- type Counter
- func (c Counter) Apply(ctx changes.Context, cx changes.Change) changes.Value
- func (c Counter) ApplyCollection(ctx changes.Context, cx changes.Change) changes.Collection
- func (c Counter) Count() int
- func (c Counter) Increment(by int32) changes.Change
- func (c Counter) Set(v int32) changes.Change
- func (c Counter) Slice(offset, count int) changes.Collection
- type Generic
- type M
- type S16
- func (s S16) Apply(ctx changes.Context, c changes.Change) changes.Value
- func (s S16) ApplyCollection(ctx changes.Context, c changes.Change) changes.Collection
- func (s S16) Count() int
- func (s S16) FromUTF16(idx int) int
- func (s S16) Slice(offset, count int) changes.Collection
- func (s S16) ToUTF16(idx int) int
- type S8
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type A ¶
The A type represents a slice of arbitrary values. It implements the changes.Value interface. The actual elements can be nil (unlike the regular requirement for values to be non-nil). Nil values are treated as if they were changes.Nil
func (A) Apply ¶
Apply applies the change and returns the updated value
Note: deleting an element via changes.Replace simply replaces it with nil. It does not actually remove the element -- that needs a changes.Splice.
func (A) ApplyCollection ¶
ApplyCollection implements changes.Collection
type Counter ¶
type Counter int32
Counter implements a 32-bit counter that can be incremented, decremented or replaced. Counter implements the changes.Value interface.
func (Counter) ApplyCollection ¶
ApplyCollection implements Collection interface
type Generic ¶
type Generic struct { Get func(key interface{}) changes.Value Set func(key interface{}, v changes.Value) changes.Value Splice func(offset, count int, insert changes.Collection) changes.Collection }
Generic is a helper to build value and collection types
func (Generic) Apply ¶
Apply applies a change to produce a new value. Note that this requires the current value as input unlike changes.Value.
func (Generic) ApplyCollection ¶
func (g Generic) ApplyCollection(ctx changes.Context, c changes.Change, current changes.Collection) changes.Collection
ApplyCollection implements changes.ApplyCollection but with using the provided current value and the helper functions
type M ¶
The M type represents a map of arbitrary key/values. It implements the changes.Value interface. As with all values, a nil value should be expressed via changes.Atomic{nil} to distinguish it from an attempt to remove a key.
type S16 ¶
type S16 string
S16 implements string with offsets and counts referring to utf16 runes. The UTF16 offsets map to native Javascript string offsets.
func (S16) ApplyCollection ¶
ApplyCollection implements changes.Collection
func (S16) FromUTF16 ¶
FromUTF16 converts an UTF16 offset into a regular string offset It panics if the UTF16 offset lies within a UTF32 character