models

package
v1.0.2-0...-c3ad2af Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

type Predicate func(*Todo) bool

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

func (t *Todo) Completed() bool

Completed returns true iff the todo is completed. It operates as a getter for the completed property.

func (*Todo) Id

func (t *Todo) Id() string

Id is a getter for the id property.

func (Todo) MarshalJSON

func (t Todo) MarshalJSON() ([]byte, error)

MarshalJSON converts the todo to json.

func (*Todo) Remaining

func (t *Todo) Remaining() bool

Remaining returns true iff the todo is not completed.

func (*Todo) Remove

func (t *Todo) Remove()

Remove removes the todo from the list.

func (*Todo) SetCompleted

func (t *Todo) SetCompleted(completed bool)

SetCompleted is a setter for the completed property. After the property is set, it broadcasts that the todo list was changed.

func (*Todo) SetTitle

func (t *Todo) SetTitle(title string)

SetTitle is a setter for the title property.

func (*Todo) Title

func (t *Todo) Title() string

Title is a getter for the title property.

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

func (t *Todo) UnmarshalJSON(data []byte) error

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) AddTodo

func (list *TodoList) AddTodo(title string)

AddTodo appends a new todo to the list.

func (TodoList) All

func (list TodoList) All() []*Todo

All returns all the todos. It applies a filter using the All predicate.

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

func (list TodoList) Completed() []*Todo

Completed returns only those todos which are completed. It applies a filter using the Completed predicate.

func (*TodoList) DeleteById

func (list *TodoList) DeleteById(id string)

DeleteById removes the todo with the given id from the list.

func (TodoList) Filter

func (list TodoList) Filter(f Predicate) []*Todo

Filter returns a slice todos for which the predicate is true. The returned slice is a subset of all todos.

func (*TodoList) Load

func (list *TodoList) Load() error

Load loads the list of todos from the datastore.

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

func (list TodoList) Remaining() []*Todo

Remaining returns only those todos which are remaining (or active). It applies a filter using the Remaining predicate.

func (TodoList) Save

func (list TodoList) Save() error

Save saves the list of todos to the datastore.

func (*TodoList) UncheckAll

func (list *TodoList) UncheckAll()

UncheckAll unchecks all the todos in the list, causing them to be in the active/remaining state.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL