~gioverse/chat

7e2050cb099eb3cb9a8ad24824f796237d2ad490 — Chris Waldon 1 year, 8 months ago 38234cc
list: add field indicating type of state update

This commit adds a field describing what triggered a given state
update.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
1 files changed, 25 insertions(+), 0 deletions(-)

M list/async.go
M list/async.go => list/async.go +25 -0
@@ 4,6 4,28 @@ import (
	"fmt"
)

type updateType uint8

const (
	// pull indicates the results from a load request. The update pulled
	// data from the data store.
	pull updateType = iota
	// push indicates the results from an asynchronous insertion of
	// data. The application pushed data to the list.
	push
)

func (u updateType) String() string {
	switch u {
	case pull:
		return "pull"
	case push:
		return "push"
	default:
		return "unknown"
	}
}

// stateUpdate contains a new slice of element data and a mapping from all of
// the element serials to their respective indicies. This data structure is designed
// to allow the UI code to quickly find and update any offsets and locations


@@ 15,6 37,7 @@ type stateUpdate struct {
	// Ignore reports which directions (if any) the async backend currently
	// believes to have no new content.
	Ignore Direction
	Type   updateType
}

func (s stateUpdate) String() string {


@@ 56,6 79,7 @@ func asyncProcess(maxSize int, hooks Hooks) (chan<- interface{}, chan viewport, 
				}
				switch req := req.(type) {
				case modificationRequest:
					su.Type = push
					newElems = req.NewOrUpdate
					rmSerials = req.Remove
					updateOnly = req.UpdateOnly


@@ 86,6 110,7 @@ func asyncProcess(maxSize int, hooks Hooks) (chan<- interface{}, chan viewport, 
					})
					ignore = NoDirection
				case loadRequest:
					su.Type = pull
					viewport = req.viewport
					if ignore.Contains(req.Direction) {
						continue