Code Explainers

Code explainers tagged #state machine

javascript
import { createContext, useContext, useReducer, useCallback, useEffect } from 'react';
 
const AuthContext = createContext(null);
 

Building an auth context in React

context usereducer authentication
Intermediate 8 steps
ruby
class Order < ApplicationRecord
  include AASM
 
  belongs_to :warehouse

Modeling an order lifecycle with AASM in Rails

state machine guards callbacks
Intermediate 10 steps
rust
#[derive(Debug, PartialEq)]
enum State {
    FieldStart,
    InUnquoted,

Parsing a CSV line with a state machine

state machine parsing enums
Intermediate 9 steps
php
<?php
 
namespace App\Models;
 

How Eloquent scopes model order status in Laravel

query scopes state machine eloquent
Intermediate 7 steps
rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum State {
    Locked,
    Unlocked,

A turnstile state machine in Rust

state machine enums pattern matching
Intermediate 9 steps