Skip to content

Commit

Permalink
Action: Don't trust condition changed events too much
Browse files Browse the repository at this point in the history
  • Loading branch information
lxn committed May 1, 2013
1 parent 13be995 commit d8dca98
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,14 @@ func (a *Action) SetEnabledCondition(c Condition) {
a.enabledCondition = c

if c != nil {
a.enabled = c.Satisfied()

a.enabledConditionChangedHandle = c.Changed().Attach(func() {
a.raiseChanged()
if a.enabled != c.Satisfied() {
a.enabled = !a.enabled

a.raiseChanged()
}
})
}
}
Expand Down Expand Up @@ -248,8 +254,14 @@ func (a *Action) SetVisibleCondition(c Condition) {
a.visibleCondition = c

if c != nil {
a.visible = c.Satisfied()

a.visibleConditionChangedHandle = c.Changed().Attach(func() {
a.raiseVisibleChanged()
if a.visible != c.Satisfied() {
a.visible = !a.visible

a.raiseVisibleChanged()
}
})
}
}
Expand Down

0 comments on commit d8dca98

Please sign in to comment.