Skip to content

Instantly share code, notes, and snippets.

View ctrlplusb's full-sized avatar
📢

Sean Matheson ctrlplusb

📢
View GitHub Profile
@ctrlplusb
ctrlplusb / findManyCursor.test.ts
Last active February 18, 2022 17:22
Utility to provide Relay Cursor Connection Specification support to Prisma Framework
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,
@ctrlplusb
ctrlplusb / superagent-mock-example.js
Last active July 1, 2020 07:38
Stripped down and basic example of testing superagent based code using superagent-mock and mocha.
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 is intentionally blank just and exists to secure a decent gist name */
@ctrlplusb
ctrlplusb / store.ts
Last active February 10, 2019 00:01
import { createStore } from 'easy-peasy';
import { StoreModel } from './model';
// 👇
const store = createStore<StoreModel>({
todos: {
items: ["Install easy-peasy", "Build app", "profit"]
},
notification: {
msg: ""
const store = createStore<StoreModel>({
todos: {
// ...
add: (state, payload) => {
return {
...state,
items: [
...state.items,
payload
]
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)
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");
import { Action } from "easy-peasy";
type TodosModel = {
items: string[];
add: Action<TodosModel, string>; // 👈
}
type NotificationModel = {
msg: string;
set: Action<NotificationModel, string>; // 👈
export default function Todos() {
const items = useStore(state => state.todos.items);
// 👇
const save = useActions(actions => actions.todos.save);
const [newTodo, setNewTodo] = useState("");
return (
<div>
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