Skip to content

Commit

Permalink
ref(opts): remove apply from pref (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Sep 11, 2024
1 parent 94137e9 commit 83f023c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
29 changes: 0 additions & 29 deletions internal/opts/get.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package opts

import (
"io/fs"

"github.com/snivilised/traverse/pref"
)

Expand Down Expand Up @@ -37,30 +35,3 @@ func GetWith(o *pref.Options) *Binder {

return binder
}

type ActiveState struct {
}

type LoadInfo struct {
O *pref.Options
State *ActiveState
WakeAt string
}

// put this into file load
func Load(_ fs.FS, from string, settings ...pref.Option) (*LoadInfo, *Binder, error) {
o := pref.DefaultOptions()
// do load
_ = from
binder := NewBinder()
o.Events.Bind(&binder.Controls)

// TODO: save any active state on the binder, eg the wake point

err := apply(o, settings...)

return &LoadInfo{
O: o,
WakeAt: "tbd",
}, binder, err
}
24 changes: 24 additions & 0 deletions internal/opts/load.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package opts

import (
"io/fs"

"github.com/snivilised/traverse/pref"
)

func Load(_ fs.FS, from string, settings ...pref.Option) (*LoadInfo, *Binder, error) {
o := pref.DefaultOptions()
// do load
_ = from
binder := NewBinder()
o.Events.Bind(&binder.Controls)

// TODO: save any active state on the binder, eg the wake point

err := apply(o, settings...)

return &LoadInfo{
O: o,
WakeAt: "tbd",
}, binder, err
}
16 changes: 16 additions & 0 deletions internal/opts/opts-defs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package opts

import (
"github.com/snivilised/traverse/pref"
)

// 📦 pkg: opts - internal options handling

type ActiveState struct {
}

type LoadInfo struct {
O *pref.Options
State *ActiveState
WakeAt string
}
14 changes: 0 additions & 14 deletions pref/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ type (
Option func(o *Options) error
)

func apply(o *Options, settings ...Option) (err error) {
for _, option := range settings {
if option != nil {
err = option(o)

if err != nil {
return err
}
}
}

return
}

// IfOption enables options to be conditional. IfOption condition evaluates to true
// then the option is returned, otherwise nil.
func IfOption(condition bool, option Option) Option {
Expand Down

0 comments on commit 83f023c

Please sign in to comment.