Set.prototype.toggle

dante federici c.dante.federici at gmail.com
Sun Oct 29 18:17:29 UTC 2017


I guess a better way to phrase my argument is:

What situation are you in where you don't know the current state?

That is, consider the following:


```
if (enabled) {
  set render state to "enabled", set action to "delete"
} else {
  set render state to "disabled", set action to "add"
}
```

versus:

```
set action to "toggle"
if (enabled) {
  set render state to "enabled"
} else {
  set render state to "disabled"
}
```

What I'm trying to say is that "toggle" is ambiguous without checking the
current state. Adding a set toggle method only serves to allow "drift" --
where you have a state assumption of "enabled" but the set is actually
disabled, or vice versa. Set should be explicit -- this doesn't mean you
need to litter your code with guards, but instead the state of an
application using a set should know if it needs to remove or add, and the
use of a "toggle" implies the state of the set is ambiguous. Either way. I
don't think the UI checkbox use case is compelling enough to add to the
prototype for Set.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20171029/7880ff4e/attachment-0001.html>


More information about the es-discuss mailing list