Skip to content

Instantly share code, notes, and snippets.

View wolverineks's full-sized avatar
🌴
On vacation

Kevin Sullivan wolverineks

🌴
On vacation
View GitHub Profile
@wolverineks
wolverineks / machine.js
Last active December 6, 2019 20:14
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
import React, { PropTypes, Component } from 'react';
import ReactDOM from 'react-dom';
import './blank.css';
import Details from './Details';
import {
Panel,
Button,
PageHeader,
ControlLabel,
FormControl,
@wolverineks
wolverineks / jsx-test.js
Created November 29, 2018 15:20
Experiment with using JSX to write tests
// @flow
/* globals describe it expect */
import Renderer from 'react-test-renderer'
/** @jsx convert */
const convert = (component, props, children) => {
const args = { ...props, children }
return component(args)
}
@wolverineks
wolverineks / Connection.js
Last active August 12, 2018 18:14
Connection Component
// Redux:
const INCREMENT = 'INCREMENT'
const increment = () => ({ type: INCREMENT })
const DECREMENT = 'DECREMENT';
const decrement = () => ({ type: DECREMENT })
const count = (state = 0, action) => {
switch (action.type) {
case INCREMENT: {
@wolverineks
wolverineks / GetterComponents.jsx
Created May 23, 2018 23:04
Getter Components
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component, PureComponent } from 'react';
import {
Platform,
Text,
const ifType = type => cb => item => typeof item === type ? cb(item) : item
const ifNumber = ifType('number')
const isDivisibleBy = divisor => num => num % divisor === 0
const isFizz = isDivisibleBy(3)
const isBuzz = isDivisibleBy(5)
const isBang = isDivisibleBy(15)
const convert = predicate => converted => num => predicate(num) ? converted : num
const toFizz = convert(isFizz)('fizz')
@wolverineks
wolverineks / declarativeRouterAPI.ts
Last active April 27, 2018 14:07
Declarative Router API
import { Bodies, Body, Drawers, Drawer, Headers, Header, Router, Route, Tabs, Tab } from 'declarative-router'
import { Scene1, Scene2 } from './myScenes'
import { Main } from './myRoutes'
<Router>{(route) =>
// ROUTES ////////////////////////////////////////////////////////////////
<Route isActive={route === 'main'}>{(scene) =>
<Scene isActive={scene === '1'}>
// DRAWERS ////////////////////////////////////////////////////////////////
<Drawers>
@wolverineks
wolverineks / GetBook.js
Last active May 6, 2018 13:48
Recreating Async / Await
// Types ///////////////////////////////////////////////////////////////////
type BookId = string
type BookTitle = string
type BookAuthor = string
type BookRating = number
type AuthorName = string
type AuthorId = number
type Author = {
name: AuthorName,
@wolverineks
wolverineks / InteractiveModal.jsx
Created March 31, 2018 06:39
Compound Components
// @flow
import React, { Component } from 'react'
import type { Node } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { default as Modal } from 'react-native-modal'
import { styles } from './styles.js'
// CONTAINER /////////////////////////////////////////////////////////////////////////////
@wolverineks
wolverineks / 000-helperTypes.js
Created February 6, 2018 20:04
Proposed Redux State
export type WalletId = string
export type CurrencyCode = string
export type IsoCurrencyCode = string
export type PluginName = string
export type SceneKey = string
export type SceneData = Object