This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Country, Photon } from '@prisma/photon'; | |
import { findManyCursor } from './findManyCursor'; | |
const photon = new Photon(); | |
let data: Country[]; | |
const createCountry = async (id: string) => photon.countries.create({ | |
data: { | |
id, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { expect } from 'chai'; | |
import superagent from 'superagent'; | |
import mockSuperagent from 'superagent-mock'; | |
import * as Errors from '../../../common/utils/errors'; | |
// Under test. | |
import login from './login'; | |
describe(`login api`), () => { | |
const serverEndPoint = `http://foobar.com/login`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This is intentionally blank just and exists to secure a decent gist name */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from 'easy-peasy'; | |
import { StoreModel } from './model'; | |
// 👇 | |
const store = createStore<StoreModel>({ | |
todos: { | |
items: ["Install easy-peasy", "Build app", "profit"] | |
}, | |
notification: { | |
msg: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const store = createStore<StoreModel>({ | |
todos: { | |
// ... | |
add: (state, payload) => { | |
return { | |
...state, | |
items: [ | |
...state.items, | |
payload | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { StoreProvider, createStore, useStore, useActions } from 'easy-peasy'; | |
// 👇 create your store, providing the model | |
const store = createStore({ | |
todos: { | |
items: ['Install easy-peasy', 'Build app', 'Profit'], | |
// 👇 define actions directly on your model | |
add: (state, payload) => { | |
// do simple mutation to update state, and we make it an immutable update | |
state.items.push(payload) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { render } from "react-dom"; | |
import { StoreProvider } from "easy-peasy"; // 👈 | |
import store from "./store"; | |
render( | |
<StoreProvider store={store}> | |
<App /> | |
</StoreProvider>, | |
document.querySelector("#root"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Action } from "easy-peasy"; | |
type TodosModel = { | |
items: string[]; | |
add: Action<TodosModel, string>; // 👈 | |
} | |
type NotificationModel = { | |
msg: string; | |
set: Action<NotificationModel, string>; // 👈 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function Todos() { | |
const items = useStore(state => state.todos.items); | |
// 👇 | |
const save = useActions(actions => actions.todos.save); | |
const [newTodo, setNewTodo] = useState(""); | |
return ( | |
<div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { thunk } from "easy-peasy"; // 👈 | |
const store = createStore<StoreModel>({ | |
todos: { | |
items: ["Install easy-peasy", "Build app", "profit"], | |
// 👇renamed | |
saved: (state, payload) => { | |
state.items.push(payload); | |
}, | |
// 👇our thunk |
NewerOlder