forked from andreaskoch/allmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository.go
77 lines (62 loc) · 1.89 KB
/
repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2014 Andreas Koch. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package dataaccess
import (
"github.com/andreaskoch/allmark/common/route"
"fmt"
)
type PathProvider interface {
Path() string
}
type RoutesProvider interface {
Routes() []route.Route
}
type ItemsProvider interface {
Items() []Item
Item(route route.Route) Item
}
type Subscriber interface {
Subscribe(updates chan Update)
}
type LiveReload interface {
StartWatching(route route.Route)
StopWatching(route route.Route)
}
type Repository interface {
PathProvider
ItemsProvider
RoutesProvider
Subscriber
LiveReload
}
// NewUpdate creates a new Update instance from the given new, modified and deleted routes.
func NewUpdate(newItemRoutes, modifiedItemRoutes, deletedItemRoutes []route.Route) Update {
return Update{newItemRoutes, modifiedItemRoutes, deletedItemRoutes}
}
// Update contains a list of new, modified and deleted routes.
type Update struct {
newItemRoutes []route.Route
modifiedItemRoutes []route.Route
deletedItemRoutes []route.Route
}
func (update *Update) String() string {
return fmt.Sprintf("Update (New: %v, Modified: %v, Deleted: %v)",
len(update.newItemRoutes), len(update.modifiedItemRoutes), len(update.deletedItemRoutes))
}
// IsEmpty indicates whether this Update is empty or not.
func (update *Update) IsEmpty() bool {
return len(update.newItemRoutes) == 0 && len(update.modifiedItemRoutes) == 0 && len(update.deletedItemRoutes) == 0
}
// New returns the routes of new items.
func (update *Update) New() []route.Route {
return update.newItemRoutes
}
// Modified returns the routes of modified items.
func (update *Update) Modified() []route.Route {
return update.modifiedItemRoutes
}
// Deleted returns the routes of releted items.
func (update *Update) Deleted() []route.Route {
return update.deletedItemRoutes
}