Skip to content

Instantly share code, notes, and snippets.

@Onurbon
Onurbon / ChatApp.tsx
Last active October 17, 2019 23:19
ChatApp.tsx
import { query } from "@prodo/firebase-plugins";
function ChatApp({}) {
const { db, state } = useData();
const messages = query(db.messages).where("room", "==", state.roomId);
return (
<div>
<RoomSelector />
{messages.map(({ key }) => (
<Message id={key} />
@Onurbon
Onurbon / PostMessage.tsx
Created October 17, 2019 22:51
PostMessage.tsx
function PostMessage() {
const { postMessage } = useActions();
return (
<input
placeholder="say something nice"
onKeyUp={e => {
if (e.keyCode === 13 /* enter */) {
postMessage(e.target.value);
}
}}
@Onurbon
Onurbon / RoomSelector.tsx
Created October 17, 2019 22:49
RoomSelector.tsx
function RoomSelector() {
const { state } = useData();
const { setRoom } = useActions();
return (
<input
value={state.roomId}
onChange={e => {
setRoom(e.target.value);
}}
/>
@Onurbon
Onurbon / Message.tsx
Created October 17, 2019 22:49
Message.tsx
function Message({ id }) {
const { db } = useData();
const { likeMessage } = useActions();
return (
<div>
<h2>{db.messages[id].text}</h2>
<span>{db.messages[id].likes}</span>
<button onClick={() => likeMessage(id)}>+1</button>
</div>
);
@Onurbon
Onurbon / imports.ts
Created October 17, 2019 22:48
imports
import { useData } from "./data";
import { useActions } from "./actions";
@Onurbon
Onurbon / actions.ts
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++;
}
@Onurbon
Onurbon / data.ts
Created October 17, 2019 22:44
data.ts
import { dataModel } from "@prodo/core";
import { authPlugin, dbPlugin } from "@prodo/firebase-plugins";
const data = dataModel<{
state: {
roomId: string;
message: string;
};
auth: {
username: string;
@Onurbon
Onurbon / 0_reuse_code.js
Last active August 29, 2015 14:17
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Onurbon
Onurbon / gist:9316101
Last active August 29, 2015 13:56
YASPER: Yet Another Speed Reader (Tampermonkey script for Chrome)
// ************************************
// * YASPER: Yet Another Speed Reader *
// ************************************
// This is a Tampermonkey script for speed-reading in Chrome.
// Configure the list of matched pages as usual (default = @match http*://*.wikipedia.org/*).
// Whenever a sentence of paragraph is selected, a single-world speed reader pops up below the cursor.
// Typical usage: triple-click on the first word of a paragraph to start speed-reading it.
// Tip 1: read the first few words of the paragraph before triple-clicking.
// Tip 2: for more efficiency, start scrolling down to the next paragraph while speed-reading.