Skip to content

Instantly share code, notes, and snippets.

@Onurbon
Created October 17, 2019 22:47
actions.ts
import { actionsProxy, memo } from "@prodo/core";
import { db, state, auth } from "./data";
import { newId } from "./effects"
function setRoom(id: string) {
state.roomId = id;
}
function likeMessage(id: string) {
db.messages[id].likes++;
}
function postMessage() {
const id = newId();
db.messages[newId] = {
text: state.message,
author: auth.username,
likes: 0,
roomId: state.roomId
};
}
export const useActions = actionsProxy({
setRoomId,
likeMessage,
postMessage
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment