Skip to content

Commit

Permalink
Deprecate NewModel() constructors; use New() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
meowgorithm committed Jan 11, 2022
1 parent 9401ebb commit b35f96c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
9 changes: 7 additions & 2 deletions help/help.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions list/list.go
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions paginator/paginator.go
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions progress/progress.go
Expand Up @@ -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,
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions spinner/spinner.go
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion textinput/textinput.go
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit b35f96c

Please sign in to comment.