Deprecate NewModel() constructors; use New() instead

This commit is contained in:
Christian Rocha 2022-01-10 18:27:33 -05:00
parent 9401ebbb83
commit b35f96cd2d
6 changed files with 41 additions and 11 deletions

View File

@ -57,8 +57,8 @@ type Model struct {
Styles Styles Styles Styles
} }
// NewModel creates a new help view with some useful defaults. // New creates a new help view with some useful defaults.
func NewModel() Model { func New() Model {
keyStyle := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{ keyStyle := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
Light: "#909090", Light: "#909090",
Dark: "#626262", Dark: "#626262",
@ -90,6 +90,11 @@ func NewModel() Model {
} }
} }
// NewModel creates a new help view with some useful defaults.
//
// Deprecated. Use New instead.
var NewModel = New
// Update helps satisfy the Bubble Tea Model interface. It's a no-op. // Update helps satisfy the Bubble Tea Model interface. It's a no-op.
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil return m, nil

View File

@ -149,8 +149,8 @@ type Model struct {
delegate ItemDelegate delegate ItemDelegate
} }
// NewModel returns a new model with sensible defaults. // New returns a new model with sensible defaults.
func NewModel(items []Item, delegate ItemDelegate, width, height int) Model { func New(items []Item, delegate ItemDelegate, width, height int) Model {
styles := DefaultStyles() styles := DefaultStyles()
sp := spinner.NewModel() sp := spinner.NewModel()
@ -196,6 +196,11 @@ func NewModel(items []Item, delegate ItemDelegate, width, height int) Model {
return m return m
} }
// NewModel returns a new model with sensible defaults.
//
// Deprecated. Use New instead.
var NewModel = New
// SetFilteringEnabled enables or disables filtering. Note that this is different // SetFilteringEnabled enables or disables filtering. Note that this is different
// from ShowFilter, which merely hides or shows the input view. // from ShowFilter, which merely hides or shows the input view.
func (m *Model) SetFilteringEnabled(v bool) { func (m *Model) SetFilteringEnabled(v bool) {

View File

@ -96,8 +96,8 @@ func (m Model) OnLastPage() bool {
return m.Page == m.TotalPages-1 return m.Page == m.TotalPages-1
} }
// NewModel creates a new model with defaults. // New creates a new model with defaults.
func NewModel() Model { func New() Model {
return Model{ return Model{
Type: Arabic, Type: Arabic,
Page: 0, Page: 0,
@ -114,6 +114,11 @@ func NewModel() Model {
} }
} }
// NewModel creates a new model with defaults.
//
// Deprecated. Use New instead.
var NewModel = New
// Update is the Tea update function which binds keystrokes to pagination. // Update is the Tea update function which binds keystrokes to pagination.
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) { func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {

View File

@ -154,8 +154,8 @@ type Model struct {
scaleRamp bool scaleRamp bool
} }
// NewModel returns a model with default values. // New returns a model with default values.
func NewModel(opts ...Option) Model { func New(opts ...Option) Model {
m := Model{ m := Model{
id: nextID(), id: nextID(),
Width: defaultWidth, Width: defaultWidth,
@ -176,6 +176,11 @@ func NewModel(opts ...Option) Model {
return m return m
} }
// NewModel returns a model with default values.
//
// Deprecated. Use New instead.
var NewModel = New
// Init exists satisfy the tea.Model interface. // Init exists satisfy the tea.Model interface.
func (m Model) Init() tea.Cmd { func (m Model) Init() tea.Cmd {
return nil return nil

View File

@ -193,14 +193,19 @@ func (m Model) Visible() bool {
return !m.hidden() && !m.finished() return !m.hidden() && !m.finished()
} }
// NewModel returns a model with default values. // New returns a model with default values.
func NewModel() Model { func New() Model {
return Model{ return Model{
Spinner: Line, Spinner: Line,
id: nextID(), id: nextID(),
} }
} }
// NewModel returns a model with default values.
//
// Deprecated. Use New instead.
var NewModel = New
// TickMsg indicates that the timer has ticked and we should render a frame. // TickMsg indicates that the timer has ticked and we should render a frame.
type TickMsg struct { type TickMsg struct {
Time time.Time Time time.Time

View File

@ -153,7 +153,7 @@ type Model struct {
} }
// NewModel creates a new model with default settings. // NewModel creates a new model with default settings.
func NewModel() Model { func New() Model {
return Model{ return Model{
Prompt: "> ", Prompt: "> ",
BlinkSpeed: defaultBlinkSpeed, BlinkSpeed: defaultBlinkSpeed,
@ -174,6 +174,11 @@ func NewModel() Model {
} }
} }
// NewModel creates a new model with default settings.
//
// Deprecated. Use New instead.
var NewModel = New
// SetValue sets the value of the text input. // SetValue sets the value of the text input.
func (m *Model) SetValue(s string) { func (m *Model) SetValue(s string) {
runes := []rune(s) runes := []rune(s)