index.js 452 B

1234567891011121314151617181920212223
  1. 'use strict'
  2. module.exports = factory
  3. // Construct a state `toggler`: a function which inverses `property` in context
  4. // based on its current value.
  5. // The by `toggler` returned function restores that value.
  6. function factory(key, state, ctx) {
  7. return enter
  8. function enter() {
  9. var context = ctx || this
  10. var current = context[key]
  11. context[key] = !state
  12. return exit
  13. function exit() {
  14. context[key] = current
  15. }
  16. }
  17. }