Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm working on a digital version of a board game. It's 2-4 players, turn based. Im using Rust (actix) on the backend for learning purposes; React, redux, immer on frontend. Communication via Server-Sent Events.

Im experimenting with redux-like contstructs, which reduce the boilerplatey stuff, for example:

    export function setStatePlain(state: State) {
        return {
            type: SET_STATE,
            payload: state,
        } as const;
    }
    
    export function setState(state: DeepPartial<State>): Thunk {
        return (dispatch, getState) => {
            dispatch(setStatePlain(Object.assign({}, getState(), state)));
        };
    }
    
    export function someAction(data: Data): Thunk {
        ...
        dispatch(setState(immer.produce(getState(), state => {
            state.lobbyGames[result.data.uuid] = {
                ...result.data,
                adminId: state.playerId,
                players: [{
                    id: state.playerId,
                    name: state.playerName,
                    ready: false,
                }],
            };
            ...
        }
    })));


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: