Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
Add Comment
Please, Sign In to add comment