Skip to content

Instantly share code, notes, and snippets.

View ShMcK's full-sized avatar

Shawn McKay ShMcK

View GitHub Profile
@ShMcK
ShMcK / SketchSystems.spec
Last active June 17, 2018 00:01
DrawerOpen*
DrawerOpen*
loadTape -> HasTape
closeDrawer -> NoTape
DrawerClosed
eject -> DrawerOpen
NoTape
HasTape*
@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
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 / 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
 }
@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 / 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 / WalkmanStateMachineComplex.jsx
Last active July 17, 2018 02:54
VisualizingState: Walkman State Machine + Complexity
const events = {
  STOP: 'Stopped',
  PLAY: 'Playing',
  REWIND: 'Rewinding',
  FASTFORWARD: 'FastForwarding',
 }
class Walkman extends React.Component {
 state = {
  current: events.STOP,
@ShMcK
ShMcK / WalkmanStateMachineGuard.jsx
Last active July 18, 2018 02:12
Visualizing State: Walkman State Machine Guard
 const events = {
  STOP: 'Stopped',
  PLAY: 'Playing',
  REWIND: 'Rewinding',
  FASTFORWARD: 'FastForwarding',
 }
class Walkman extends React.Component {
 transition = (target) => {
  const preventTapeJam =
@ShMcK
ShMcK / WalkmanStateMachineGuard2.jsx
Last active July 17, 2018 03:02
VisualizingState: Walkman State Machine Guard 2
class Walkman extends React.Component {
 transition = (event) => {
  const preventTapeJam = /* ... */
  const shouldEject = event === 'STOP' && this.state.current === 'Stopped'
 
  if (!preventTapeJam) {
  /* … */
  } else if (shouldEject) {
  this.setState({ current: events.EJECT })
  }
@ShMcK
ShMcK / FiniteStates.js
Created July 7, 2018 21:50
FiniteStatesSimplification
const events = {
STOP: 'Stopped',
PLAY: 'Playing'
}