Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdata committed Dec 6, 2024
1 parent e486909 commit b8afc85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func TestBindFunc_String(t *testing.T) {

testBind_Hooks(t, "foo")
testBind_StringSetter(t, Bind(&mu, &val).(StringSetter))
testBind_StringSetter(t, Bind(&mu, &val).Success(func() (err error) { return }).(StringSetter))
testBind_StringSetter(t, Bind(&mu, &val).Success(func() {}).(StringSetter))
}

func testBind_FloatSetter(t *testing.T, v FloatSetter) {
Expand All @@ -291,7 +291,7 @@ func TestBindFunc_Float(t *testing.T) {

testBind_Hooks(t, float64(1.23))
testBind_FloatSetter(t, Bind(&mu, &val).(FloatSetter))
testBind_FloatSetter(t, Bind(&mu, &val).Success(func() (err error) { return }).(FloatSetter))
testBind_FloatSetter(t, Bind(&mu, &val).Success(func() {}).(FloatSetter))
}

func testBind_BoolSetter(t *testing.T, v BoolSetter) {
Expand All @@ -310,7 +310,7 @@ func TestBindFunc_Bool(t *testing.T) {

testBind_Hooks(t, true)
testBind_BoolSetter(t, Bind(&mu, &val).(BoolSetter))
testBind_BoolSetter(t, Bind(&mu, &val).Success(func() (err error) { return }).(BoolSetter))
testBind_BoolSetter(t, Bind(&mu, &val).Success(func() {}).(BoolSetter))
}

func testBind_TimeSetter(t *testing.T, v TimeSetter) {
Expand All @@ -329,5 +329,5 @@ func TestBindFunc_Time(t *testing.T) {

testBind_Hooks(t, time.Now())
testBind_TimeSetter(t, Bind(&mu, &val).(TimeSetter))
testBind_TimeSetter(t, Bind(&mu, &val).Success(func() (err error) { return }).(TimeSetter))
testBind_TimeSetter(t, Bind(&mu, &val).Success(func() {}).(TimeSetter))
}
6 changes: 6 additions & 0 deletions binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ type Binder[T comparable] interface {
//
// The lock will be held at this point.
// Do not lock or unlock the Binder within fn. Do not call JawsSet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsSetLocked first.
SetLocked(fn BindSetHook[T]) (newbind Binder[T])

// GetLocked returns a Binder[T] that will call fn instead of JawsGetLocked.
//
// The lock will be held at this point, preferring RLock over Lock, if available.
// Do not lock or unlock the Binder within fn. Do not call JawsGet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsGetLocked first.
GetLocked(fn BindGetHook[T]) (newbind Binder[T])

// Success returns a Binder[T] that will call fn after the value has been set
Expand Down
6 changes: 6 additions & 0 deletions binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (bind Binding[T]) RUnlock() {
//
// The lock will be held at this point.
// Do not lock or unlock the Binder within fn. Do not call JawsSet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsSetLocked first.
func (bind Binding[T]) SetLocked(setFn BindSetHook[T]) Binder[T] {
return &BindingHook[T]{
Binder: bind,
Expand All @@ -117,6 +120,9 @@ func (bind Binding[T]) SetLocked(setFn BindSetHook[T]) Binder[T] {
//
// The lock will be held at this point, preferring RLock over Lock, if available.
// Do not lock or unlock the Binder within fn. Do not call JawsGet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsGetLocked first.
func (bind Binding[T]) GetLocked(setFn BindGetHook[T]) Binder[T] {
return &BindingHook[T]{
Binder: bind,
Expand Down
6 changes: 6 additions & 0 deletions bindinghook.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func (bind *BindingHook[T]) JawsSetTime(elem *Element, value time.Time) error {
//
// The lock will be held at this point.
// Do not lock or unlock the Binder within fn. Do not call JawsSet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsSetLocked first.
func (bind *BindingHook[T]) SetLocked(setFn BindSetHook[T]) Binder[T] {
return &BindingHook[T]{
Binder: bind,
Expand All @@ -109,6 +112,9 @@ func (bind *BindingHook[T]) SetLocked(setFn BindSetHook[T]) Binder[T] {
//
// The lock will be held at this point, preferring RLock over Lock, if available.
// Do not lock or unlock the Binder within fn. Do not call JawsGet.
//
// The bind argument to the function is the previous Binder in the chain,
// and you probably want to call it's JawsGetLocked first.
func (bind *BindingHook[T]) GetLocked(setFn BindGetHook[T]) Binder[T] {
return &BindingHook[T]{
Binder: bind,
Expand Down

0 comments on commit b8afc85

Please sign in to comment.