remove pointer reference for models

This commit is contained in:
juancwu 2026-01-26 18:20:09 +00:00
commit 55675e0c1b
4 changed files with 32 additions and 40 deletions

View file

@ -21,7 +21,7 @@ type Model struct {
stderr string
}
func New(client *porkbun.Client) *Model {
func New(client *porkbun.Client) Model {
p := paginator.New()
p.Type = paginator.Dots
p.PerPage = 1
@ -32,7 +32,7 @@ func New(client *porkbun.Client) *Model {
s.Spinner = spinner.Dot
s.Style = lipgloss.NewStyle().Foreground(lipgloss.Color("205"))
return &Model{
return Model{
loading: false,
client: client,
domains: nil,
@ -41,11 +41,11 @@ func New(client *porkbun.Client) *Model {
}
}
func (m *Model) Init() tea.Cmd {
func (m Model) Init() tea.Cmd {
return m.spinner.Tick
}
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
var cmd tea.Cmd
switch msg := msg.(type) {
@ -89,7 +89,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
func (m *Model) View() string {
func (m Model) View() string {
if m.stderr != "" {
return fmt.Sprintf("%s\n\n(Press ctrl+c to quit)", m.stderr)
}

View file

@ -26,7 +26,7 @@ type Model struct {
err error
}
func New(cfg *config.Config) *Model {
func New(cfg *config.Config) Model {
m := Model{
cfg: cfg,
}
@ -60,14 +60,14 @@ func New(cfg *config.Config) *Model {
m.inputs[2].Width = 50
}
return &m
return m
}
func (m *Model) Init() tea.Cmd {
func (m Model) Init() tea.Cmd {
return textinput.Blink
}
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
@ -109,15 +109,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}
func (m *Model) updateInputs(msg tea.Msg) tea.Cmd {
cmds := make([]tea.Cmd, len(m.inputs))
for i := range m.inputs {
m.inputs[i], cmds[i] = m.inputs[i].Update(msg)
}
return tea.Batch(cmds...)
}
func (m *Model) View() string {
func (m Model) View() string {
var b strings.Builder
if m.mode == ModeSetup {
@ -190,3 +182,11 @@ func (m *Model) submit() (tea.Model, tea.Cmd) {
return messages.SessionReadyMsg{Client: client}
}
}
func (m *Model) updateInputs(msg tea.Msg) tea.Cmd {
cmds := make([]tea.Cmd, len(m.inputs))
for i := range m.inputs {
m.inputs[i], cmds[i] = m.inputs[i].Update(msg)
}
return tea.Batch(cmds...)
}

View file

@ -53,7 +53,7 @@ type Model struct {
output string
}
func New(client *porkbun.Client) *Model {
func New(client *porkbun.Client) Model {
items := []list.Item{
menuItem{id: domainListAll, title: "Domain: List All", desc: "List all domains in your account"},
menuItem{id: dnsRetrieveRecords, title: "DNS: Retrieve Records", desc: "Retrieve DNS records for a domain"},
@ -81,7 +81,7 @@ func New(client *porkbun.Client) *Model {
ti.CharLimit = 156
ti.Width = 20
return &Model{
return Model{
list: l,
paginator: p,
spinner: s,
@ -91,11 +91,11 @@ func New(client *porkbun.Client) *Model {
}
}
func (m *Model) Init() tea.Cmd {
func (m Model) Init() tea.Cmd {
return tea.Sequence(m.spinner.Tick)
}
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.list.SetWidth(msg.Width)
@ -138,7 +138,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, cmd
}
func (m *Model) View() string {
func (m Model) View() string {
if m.loading {
return fmt.Sprintf("\n\n %s Loading... press ctl+c to quit\n\n", m.spinner.View())
}