state

package
v0.0.0-...-865bf36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 5, 2015 License: LGPL-2.1 Imports: 3 Imported by: 10

Documentation

Overview

Model for the state of a DEJE Document.

This contains all the logic for turning events into actionable changes on a DocumentState (these actionable changes are called Primitives), and applying these primitives to the DocumentState.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container interface {
	GetChild(interface{}) (Container, error)
	SetChild(key, value interface{}) error
	RemoveChild(interface{}) error

	Export() interface{}
}

Represents a value in the tracked document state.

Its most interesting attributes, from the point of view of external API, are that it can be Traversed and Exported.

func Traverse

func Traverse(c Container, keys []interface{}) (Container, error)

Find a child based on a series of child keys. Will return an error for bad key types, unset keys, etc.

type DeletePrimitive

type DeletePrimitive struct {
	Path []interface{}
}

Corresponds to DELETE builtin event handler.

func (*DeletePrimitive) Apply

func (p *DeletePrimitive) Apply(ds *DocumentState) error

func (*DeletePrimitive) Reverse

func (p *DeletePrimitive) Reverse(ds *DocumentState) (Primitive, error)

type DocumentState

type DocumentState struct {
	Value Container
	// contains filtered or unexported fields
}

Represents the state of a document. It can be modified by applying Primitives to it, which make simple replacements or deletions to the contents at specified locations.

These transformations not only alter the DocumentState's .Value field, they also call the OnPrimitive callback, if it is set for this DocumentState.

func NewDocumentState

func NewDocumentState() *DocumentState

func (*DocumentState) Apply

func (ds *DocumentState) Apply(p Primitive) error

Apply a Primitive such that the callback (if set) is run.

Always preferable to p.Apply(ds), which does not run the callback.

func (*DocumentState) Export

func (ds *DocumentState) Export() interface{}

Return the raw, JSON-ic value of the DocumentState.

func (*DocumentState) Reset

func (ds *DocumentState) Reset()

Construct and apply a Primitive that completely resets the Value of the DocumentState to an empty JSON {}.

func (*DocumentState) SetPrimitiveCallback

func (ds *DocumentState) SetPrimitiveCallback(c OnPrimitiveCallback)

Set the OnPrimitiveCallback for this DocumentState.

type OnPrimitiveCallback

type OnPrimitiveCallback func(primitive Primitive)

An optional callback to be called for every primitive applied to a DocumentState object. Will always be called in the same order, in the same goroutine, as the Primitive application itself.

type Primitive

type Primitive interface {
	Apply(*DocumentState) error
	Reverse(*DocumentState) (Primitive, error)
}

A very simple delta for a DocumentState.

Given a *DocumentState, you can also compute a reversed version, which would UNDO the original Primitive (by taking note of the part of the DocState that the original Primitive changes, and constructing a Primitive that sets that part of the DocState to its current value).

type SetPrimitive

type SetPrimitive struct {
	Path  []interface{}
	Value interface{}
}

Corresponds to SET builtin event handler.

func (*SetPrimitive) Apply

func (p *SetPrimitive) Apply(ds *DocumentState) error

func (*SetPrimitive) Reverse

func (p *SetPrimitive) Reverse(ds *DocumentState) (Primitive, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL