Created
July 17, 2018 15:30
-
-
Save deptno/2c55100a5d5f96b17219e9c599a28052 to your computer and use it in GitHub Desktop.
immutable class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A { | |
state = { | |
x: 0, | |
y: 1 | |
} | |
constructor(initialState?: A) { | |
if (initialState) { | |
this.state = initialState | |
} | |
} | |
setX(x): A { | |
return new A({...this.state, x}) | |
} | |
setY(): void { | |
// legacy | |
} | |
} | |
const reducer = (state: A, action) => { | |
switch (action.type) { | |
case SET_X: | |
return state.setX(action.payload) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment