From 3655f5605bd8b2858f57fda5bae3fa2be228c410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 27 Jun 2019 15:50:10 -0400 Subject: [PATCH] add moar comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- keys.go | 2 ++ main.go | 5 ++++- model.go | 1 + state.go | 19 ++++++++++++------- view.go | 5 ++++- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/keys.go b/keys.go index 320c98b..2981904 100644 --- a/keys.go +++ b/keys.go @@ -11,11 +11,13 @@ type Binding struct { } func (vc *ViewController) CursorUp(g *gocui.Gui, v *gocui.View) error { + // TODO propper error handling? vc.State.SetCurrent(vc.State.GetState().Current - 1) return nil } func (vc *ViewController) CursorDown(g *gocui.Gui, v *gocui.View) error { + // TODO propper error handling? vc.State.SetCurrent(vc.State.GetState().Current + 1) return nil } diff --git a/main.go b/main.go index 1c4d7f8..3a0edc2 100644 --- a/main.go +++ b/main.go @@ -16,6 +16,7 @@ const interval = 5 var threadDone = make(chan struct{}) +// TODO Add command line options func main() { // Custom location for log messages clientLogFile, err := os.OpenFile("./app.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) @@ -38,8 +39,9 @@ func main() { log.Panicln(err) } + // Create a state wrapper. state := NewState(client) - // Subscribe rendering method to state changes + // Subscribe rendering method to state changes. state.Store.Subscribe(GenRenderFunc(g, state)) mainView := &ViewController{ @@ -78,6 +80,7 @@ func main() { TopLeft: func(mx, my int) (int, int) { return 0, (my / 2) + 1 }, BotRight: func(mx, my int) (int, int) { return mx - 1, my - 1 }, } + // TODO Create a prompt view for user convirmations. views := []*ViewController{mainView, infoView} diff --git a/model.go b/model.go index ec281d9..5baf559 100644 --- a/model.go +++ b/model.go @@ -15,6 +15,7 @@ type Model struct { } func (m *Model) Current(state PeersState, peerIndex int) PeersState { + // NOTE Not sure if I should just ignore invalid values or panic if peerIndex < 0 || peerIndex >= len(state.Peers) { return state } diff --git a/state.go b/state.go index 443bdad..4970fcd 100644 --- a/state.go +++ b/state.go @@ -8,6 +8,8 @@ import ( "github.com/dannypsnl/redux/store" ) +// This might need renaming, since it also contains the Client. +// I need the client to make the RPC calls. type State struct { Reducer *Model Store *store.Store @@ -17,27 +19,27 @@ type State struct { } func NewState(client *StatusGoClient) *State { - // Generate the reducer from our model + // Generate the reducer from our model. Reducer := &Model{ State: PeersState{ Peers: make([]Peer, 0), - Current: -1, // start with first + Current: -1, // Should mean non selected. }, } - // Instantiate the redux state from the reducer + // Instantiate the redux state from the reducer. return &State{ Reducer: Reducer, - // Define the store + // Define the store. Store: store.New(Reducer), - // Client for RPC calls + // Client for RPC calls. Client: client, - // Define available reducers for the store + // Define available reducers for the store. updatePeers: Reducer.Action(Reducer.Update), setCurrent: Reducer.Action(Reducer.Current), } } -// Helpers for shorter calls +// Helpers for shorter calls. func (s *State) Update(peers []Peer) { s.Store.Dispatch(s.updatePeers.With(peers)) } @@ -54,6 +56,8 @@ func (s *State) SetCurrent(index int) { func (s *State) GetState() PeersState { return s.Store.StateOf(s.Reducer).(PeersState) } + +// For fetching current state of peers from status-go func (s *State) Fetch() { peers, err := s.Client.getPeers() if err != nil { @@ -66,6 +70,7 @@ func (s *State) Fetch() { } } +// For removing a selected peer from connected to status-go func (s *State) Remove(peer *Peer) error { success, err := s.Client.removePeer(peer.Enode) if err != nil || success != true { diff --git a/view.go b/view.go index 0124fd7..ef88fae 100644 --- a/view.go +++ b/view.go @@ -7,6 +7,8 @@ import ( "github.com/jroimartin/gocui" ) +// Default Gocui views arent granular enough +// so I'm adding a custom one to have more control. type ViewController struct { Name string Title string @@ -22,10 +24,11 @@ type ViewController struct { SelBgColor gocui.Attribute SelFgColor gocui.Attribute Keybindings []Binding - // extra field for view state + // Extra field for view state. Might need different name. State *State } +// To combine all existing views into one type ViewManager struct { g *gocui.Gui views []*ViewController