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
}
// NewModel creates a new help view with some useful defaults.
func NewModel() Model {
// New creates a new help view with some useful defaults.
func New() Model {
keyStyle := lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{
Light: "#909090",
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.
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
return m, nil

View File

@ -149,8 +149,8 @@ type Model struct {
delegate ItemDelegate
}
// NewModel returns a new model with sensible defaults.
func NewModel(items []Item, delegate ItemDelegate, width, height int) Model {
// New returns a new model with sensible defaults.
func New(items []Item, delegate ItemDelegate, width, height int) Model {
styles := DefaultStyles()
sp := spinner.NewModel()
@ -196,6 +196,11 @@ func NewModel(items []Item, delegate ItemDelegate, width, height int) Model {
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
// from ShowFilter, which merely hides or shows the input view.
func (m *Model) SetFilteringEnabled(v bool) {

View File

@ -96,8 +96,8 @@ func (m Model) OnLastPage() bool {
return m.Page == m.TotalPages-1
}
// NewModel creates a new model with defaults.
func NewModel() Model {
// New creates a new model with defaults.
func New() Model {
return Model{
Type: Arabic,
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.
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
switch msg := msg.(type) {

View File

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

View File

@ -193,14 +193,19 @@ func (m Model) Visible() bool {
return !m.hidden() && !m.finished()
}
// NewModel returns a model with default values.
func NewModel() Model {
// New returns a model with default values.
func New() Model {
return Model{
Spinner: Line,
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.
type TickMsg struct {
Time time.Time

View File

@ -153,7 +153,7 @@ type Model struct {
}
// NewModel creates a new model with default settings.
func NewModel() Model {
func New() Model {
return Model{
Prompt: "> ",
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.
func (m *Model) SetValue(s string) {
runes := []rune(s)