Guest User

Untitled

a guest
Jul 17th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.37 KB | None | 0 0
  1. class A {
  2. state = {
  3. x: 0,
  4. y: 1
  5. }
  6.  
  7. constructor(initialState?: A) {
  8. if (initialState) {
  9. this.state = initialState
  10. }
  11. }
  12. setX(x): A {
  13. return new A({...this.state, x})
  14. }
  15. setY(): void {
  16. // legacy
  17. }
  18. }
  19.  
  20. const reducer = (state: A, action) => {
  21. switch (action.type) {
  22. case SET_X:
  23. return state.setX(action.payload)
  24. }
  25. }
Add Comment
Please, Sign In to add comment