Skip to content

Instantly share code, notes, and snippets.

View ramsaylanier's full-sized avatar

Ramsay Lanier ramsaylanier

View GitHub Profile
@ramsaylanier
ramsaylanier / Component.jsx
Created May 13, 2020 23:57
Using Pusher instead of the GraphQL subscription spec
const PageList = () => {
const [value, setValue] = React.useState('')
usePusher('pageAdded', ({ client, data }) => {
// client is an instance of ApolloClient
let { pages } = client.readQuery({ query, variables })
pages = [data, ...pages]
client.writeQuery({ query, variables, data: { pages } })
})
....
@ramsaylanier
ramsaylanier / searchResults.test.js
Last active July 11, 2019 13:01
Testing Dispatch Actions With Jest
import { useDispatch, StoreProvider } from "@/state/store"
import mockClient from "@/tests/mocks/mockClient"
import { UserQuery } from "@graphql/user/queries.graphql"
let r, data, dispatch
const DispatchWrapper = props => {
dispatch = useDispatch()
return props.children
}
@ramsaylanier
ramsaylanier / component.jsx
Last active January 31, 2019 20:52
Prefetch Hook
import React, { useState } from "react"
import usePrefetchQuery from "./usePrefetchQuery.js"
import {SomeGraphQlQuery} from "./queries.gql"
import List from "./List"
const SomeComponent = props => {
const [prefetch, setPrefetch] = useState(false)
const { data, loading } = usePrefetchQuery({query: SomeGraphQlQuery})(prefetch)
return (
@ramsaylanier
ramsaylanier / fileController.js
Created January 14, 2019 18:03
Module Docs fileController handlers
// gets directory names from a path, excluding blacklisted names. Returns an array of strings.
exports.getFiles = (path, config) => async (req, res) => {
const files = await readdir(path)
const filteredFiles = filterThroughBlacklist(files)
res.send({ files: filteredFiles, config })
}
// Gets README content for package and all first-level children.
exports.getPackage = path => async (req, res) => {
const name = req.params.name
@ramsaylanier
ramsaylanier / fileController.js
Last active January 14, 2019 17:56
Module Docs fileController
const fs = require("fs")
const pipe = require("lodash/fp/pipe")
const some = require("lodash/some")
const promisify = require("util").promisify
const readdir = promisify(fs.readdir)
const readFile = promisify(fs.readFile)
// directories to exclude from the search
const blacklist = [".bin", ".cache", ".yarn-integrity"]
@ramsaylanier
ramsaylanier / serve.js
Created January 14, 2019 17:38
Module Docs server
const express = require("express")
const webpack = require("webpack")
const config = require("../webpack.config")
const devMiddleware = require("webpack-dev-middleware")
const compiler = webpack(config)
const bodyParser = require("body-parser")
// controller to handle API requests
const FileController = require("./controllers")
@ramsaylanier
ramsaylanier / index.js
Created January 14, 2019 17:29
Module Docs cli
const program = require("commander")
const makeServer = require("./server/serve")
const path = require("path")
// gets the config file from the working directory of the application
const getConfig = () => {
const configPath = path.join(process.cwd(), "./module-docs.config.js")
const config = require(configPath)
return config ? config || null
}
const vscode = require("vscode");
const editor = vscode.window.activeTextEditor;
const rp = require("request-promise");
async function CreateGist() {
const text = editor.document.getText(editor.selection);
// User Input to name Gist file
const gistName = await vscode.window.showInputBox({
placeHolder: "Name Your GistTest"
@ramsaylanier
ramsaylanier / package.json
Created February 20, 2018 20:40
VS Code contributes example
"contributes": {
"commands": [
{
"command": "extension.createGist",
"title": "Create Gist"
}
],
"menus": {
"editor/context": [
{
@ramsaylanier
ramsaylanier / package.json
Created February 20, 2018 20:39
VS Code contributes example
"contributes": {
"commands": [
{
"command": "extension.createGist",
"title": "Create Gist"
}
],
"menus": {
"editor/context": [
{