Skip to content

Instantly share code, notes, and snippets.

@Franckapik
Created May 5, 2020 09:27
Show Gist options
  • Save Franckapik/84d32f4f6c86bf1763aeaf45ecdc8e39 to your computer and use it in GitHub Desktop.
Save Franckapik/84d32f4f6c86bf1763aeaf45ecdc8e39 to your computer and use it in GitHub Desktop.
const store = createStore({
players : {},
movement : {
up: false,
down: false,
left: false,
right: false
},
currentId : 0,
score : computed(state => state.players[state.currentId].score),
nbPlayers : computed(state => Object.keys(state.players).length),
updatePlayers : action(
(state, payload) => {state.players = payload}
),
updateData : action(
(state, payload) => ({state: {...state, ...payload}})
),
whoiam : action(
(state, payload) => {state.currentId = payload}
),
moveUP : action(
(state, payload) => {state.movement[payload] = true}
),
moveDOWN : action(
(state, payload) => {state.movement[payload] = false}
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment