Documentation
¶
Index ¶
- Variables
- type Predicate
- type Todo
- func (t *Todo) Completed() bool
- func (t *Todo) Id() string
- func (t Todo) MarshalJSON() ([]byte, error)
- func (t *Todo) Remaining() bool
- func (t *Todo) Remove()
- func (t *Todo) SetCompleted(completed bool)
- func (t *Todo) SetTitle(title string)
- func (t *Todo) Title() string
- func (t *Todo) Toggle()
- func (t *Todo) UnmarshalJSON(data []byte) error
- type TodoList
- func (list *TodoList) AddTodo(title string)
- func (list TodoList) All() []*Todo
- func (list *TodoList) CheckAll()
- func (list *TodoList) ClearCompleted()
- func (list TodoList) Completed() []*Todo
- func (list *TodoList) DeleteById(id string)
- func (list TodoList) Filter(f Predicate) []*Todo
- func (list *TodoList) Load() error
- func (list *TodoList) OnChange(f func())
- func (list TodoList) Remaining() []*Todo
- func (list TodoList) Save() error
- func (list *TodoList) UncheckAll()
Constants ¶
This section is empty.
Variables ¶
var Predicates = struct { All Predicate Completed Predicate Remaining Predicate }{ All: func(_ *Todo) bool { return true }, Completed: (*Todo).Completed, Remaining: (*Todo).Remaining, }
Predicates is a data structure with commonly used Predicates.
Functions ¶
This section is empty.
Types ¶
type Predicate ¶
Predicate is a function which takes a todo and returns a bool. It can be used in filters.
type Todo ¶
type Todo struct {
// contains filtered or unexported fields
}
Todo is the model for a single todo item.
func (*Todo) Completed ¶
Completed returns true iff the todo is completed. It operates as a getter for the completed property.
func (Todo) MarshalJSON ¶
MarshalJSON converts the todo to json.
func (*Todo) SetCompleted ¶
SetCompleted is a setter for the completed property. After the property is set, it broadcasts that the todo list was changed.
func (*Todo) Toggle ¶
func (t *Todo) Toggle()
Toggle changes whether or not the todo is completed. If it was previously completed, Toggle makes it not completed, and vice versa.
func (*Todo) UnmarshalJSON ¶
UnmarshalJSON converts json data to a todo object.
type TodoList ¶
type TodoList struct {
// contains filtered or unexported fields
}
TodoList is a model representing a list of todos.
func (*TodoList) CheckAll ¶
func (list *TodoList) CheckAll()
CheckAll checks all the todos in the list, causing them to be in the completed state.
func (*TodoList) ClearCompleted ¶
func (list *TodoList) ClearCompleted()
ClearCompleted removes all the todos from the list that have been completed.
func (TodoList) Completed ¶
Completed returns only those todos which are completed. It applies a filter using the Completed predicate.
func (*TodoList) DeleteById ¶
DeleteById removes the todo with the given id from the list.
func (TodoList) Filter ¶
Filter returns a slice todos for which the predicate is true. The returned slice is a subset of all todos.
func (*TodoList) OnChange ¶
func (list *TodoList) OnChange(f func())
OnChange can be used to register change listeners. Any functions passed to OnChange will be called when the todo list changes.
func (TodoList) Remaining ¶
Remaining returns only those todos which are remaining (or active). It applies a filter using the Remaining predicate.
func (*TodoList) UncheckAll ¶
func (list *TodoList) UncheckAll()
UncheckAll unchecks all the todos in the list, causing them to be in the active/remaining state.