|
|
|
@ -6,7 +6,7 @@ import (
|
|
|
|
|
"os" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
type Listener func(status SpaceStatus) |
|
|
|
|
type Listener func(old, new SpaceStatus) |
|
|
|
|
|
|
|
|
|
type Storage struct { |
|
|
|
|
filePath string |
|
|
|
@ -31,19 +31,20 @@ func (s *Storage) Status() SpaceStatus {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Storage) Modify(modifiers ...func(*SpaceStatus)) { |
|
|
|
|
old := s.status |
|
|
|
|
for _, m := range modifiers { |
|
|
|
|
m(&s.status) |
|
|
|
|
} |
|
|
|
|
s.notify() |
|
|
|
|
s.notify(old, s.status) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Storage) AddListener(l Listener) { |
|
|
|
|
s.listeners = append(s.listeners, l) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func (s *Storage) notify() { |
|
|
|
|
func (s *Storage) notify(old, new SpaceStatus) { |
|
|
|
|
for _, l := range s.listeners { |
|
|
|
|
l(s.status) |
|
|
|
|
l(old, new) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|