Guest User

Untitled

a guest
Jul 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. const Light = {
  2. isOn: false,
  3. turnOn() {
  4. this.isOn = true
  5. return this
  6. },
  7. turnOff() {
  8. this.isOn = false
  9. return this
  10. }
  11. }
  12.  
  13. const CommandFactory = ({ receiver, execute, unexecute }) => ({
  14. receiver,
  15. execute,
  16. unexecute
  17. })
  18.  
  19. const LightInvokerFactory = ({ on, off }) => ({
  20. on: CommandFactory(on),
  21. off: CommandFactory(off)
  22. })
  23.  
  24. const myLightInvoker = LightInvokerFactory({
  25. on: {
  26. receiver: Light,
  27. execute() {
  28. this.receiver.turnOn()
  29. return this
  30. },
  31. unexecute() {
  32. this.receiver.turnOff()
  33. return this
  34. }
  35. },
  36. off: {
  37. receiver: Light,
  38. execute() {
  39. this.receiver.turnOff()
  40. return this
  41. },
  42. unexecute() {
  43. this.receiver.turnOn()
  44. return this
  45. }
  46. }
  47. })
Add Comment
Please, Sign In to add comment