-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_predicate.go
More file actions
19 lines (15 loc) · 868 Bytes
/
read_predicate.go
File metadata and controls
19 lines (15 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package automergendjsonsync
import "github.com/automerge/automerge-go"
// A ReadPredicate is used to filter messages before receiving them in the doc.
// The function should return a bool (true=include, false=exclude/skip).
// An error will cause the sync to abort.
type ReadPredicate func(doc *automerge.Doc, msg *automerge.SyncMessage) (bool, error)
// NoReadPredicate is a ReadPredicate which includes all messages
func NoReadPredicate(doc *automerge.Doc, msg *automerge.SyncMessage) (bool, error) {
return true, nil
}
// SkipChangesReadPredicate is a ReadPredicate which skips any messages that contain changes. Effectively turning the
// doc read only since it does not accept incoming changes but is happy to doll them out.
func SkipChangesReadPredicate(doc *automerge.Doc, msg *automerge.SyncMessage) (bool, error) {
return len(msg.Changes()) == 0, nil
}