Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@ShMcK
ShMcK / WalkmanStateMachine.jsx
Last active July 17, 2018 02:56
VisualizingState: Walkman State Machine
const events = {
  STOP: 'Stopped',
  PLAY: 'Playing',
 }
class Walkman extends React.Component {
 state = {
  current: events.STOP,
 }
 transition = (event) => {
@ShMcK
ShMcK / StateComponent.jsx
Created July 1, 2018 16:22
VisualizingState: StateComponent
type States = 'loading' | 'loaded' | 'error'
type Data = any
class SomeComponent extends StateComponent<{}, States, Data> {
 state = 'loading'
 data = {}
}
@ShMcK
ShMcK / StateNotData.jsx
Created July 1, 2018 16:20
VisualizingState: State !== Data
type States = {
 mode: 'loading' | 'loaded' | 'error',
 data: any,
}
class DataLoader extends React.Component<{}, States> {
 state = {
  mode: 'loading', // state
  data: {}, // data
 }
None*
BLOCK_SELECT -> BlockEditing
TOOL_DRAW_BLOCK -> BlockDrawing
TOOL_UPLOAD_SHAPES -> UploadingShapes
TOOL_RESOURCE_VIEW -> ResourceView
BlockDrawing
BLOCK_SHAPE_COMPLETE -> BlockEditing
CANCEL_DRAWING -> None
BlockEditing
@ShMcK
ShMcK / SketchSystems.spec
Last active August 11, 2023 12:37
Ejected
Ejected
STOP -> Stopped
Stopped*
STOP -> Ejected
PLAY -> Playing
REWIND -> Rewinding
FAST_FORWARD -> FastForwarding
Active
STOP -> Stopped
PLAY -> Stopped
@ShMcK
ShMcK / SketchSystems.spec
Last active June 17, 2018 00:01
DrawerOpen*
DrawerOpen*
loadTape -> HasTape
closeDrawer -> NoTape
DrawerClosed
eject -> DrawerOpen
NoTape
HasTape*
DrawerOpen*
loadTape -> HasTape
closeDrawer -> NoTape
DrawerClosed
eject -> DrawerOpen
NoTape
HasTape*
@ShMcK
ShMcK / reactXState.js
Last active May 24, 2018 03:20
React XState Context API wrapper
import React from 'react'
const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1)
// lib, returns Context.Provider, Context.
function reactXState ({ name, machine, actions }) {
name = name || 'defaultName'
const Context = React.createContext(name)
@ShMcK
ShMcK / notification-permissions-expo.js
Created March 12, 2018 20:32
Notification Permissions
import { Permissions } from 'expo'
export default async function verifyPushNotificationsPermissions() {
const { status: existingStatus } = await Permissions.getAsync(Permissions.NOTIFICATIONS)
let finalStatus = existingStatus
// only ask if permissions have not already been determined, because
// iOS won't necessarily prompt the user a second time.
if (existingStatus !== 'granted') {
// Android remote notification permissions are granted during the app
@ShMcK
ShMcK / react-navigation-link.js
Created March 11, 2018 04:51
deep linking in react navigation