#patterns

33 snippets tagged with #patterns

typescriptintermediate

TypeScript Typed Event Emitter

Create type-safe event emitters in Node.js with full TypeScript support and autocomplete.

Best for: Type-safe pub/sub communication between modules

#nodejs#events
typescriptintermediate

Event-Driven Architecture Pattern

Build loosely coupled systems with typed event bus, async event handlers, and domain event patterns.

Best for: Microservice communication

#nodejs#events
typescriptadvanced

JavaScript Proxy Handler Pattern

Use Proxy and Reflect to create observable objects, validation layers, and dynamic API clients.

Best for: Observable state management

#nodejs#proxy
typescriptintermediate

Middleware Chain Pattern

Implement the middleware/pipeline pattern for composable request processing without Express.

Best for: Custom HTTP framework

#nodejs#middleware
typescriptintermediate

Pub/Sub Messaging Pattern

Implement publish/subscribe messaging with topics, filtered subscriptions, and message replay.

Best for: In-process event messaging

#nodejs#pubsub
typescriptadvanced

Circuit Breaker Pattern

Implements the circuit breaker pattern to prevent cascading failures when calling external services.

Best for: External API calls

#resilience#microservices
typescriptadvanced

Promise Queue with Concurrency Limit

A queue that processes async tasks with a configurable concurrency limit to prevent resource exhaustion.

Best for: Rate-limited API calls

#async#concurrency
typescriptadvanced

Compound Component Pattern

Build flexible compound components using React Context for implicit parent-child communication.

Best for: Accordion components

#patterns#compound-component
typescriptintermediate

Render Prop Pattern

Share stateful logic between components using the render prop pattern for maximum flexibility.

Best for: Mouse tracking

#patterns#render-prop
typescriptadvanced

React Compound Component Pattern

Build flexible compound components using React context for shared state between related parts.

Best for: Building flexible component libraries

#react#patterns
typescriptintermediate

React useReducer for Complex State

Manage complex component state with useReducer pattern including typed actions and middleware.

Best for: Shopping cart state management

#react#useReducer
typescriptadvanced

Context Selector Pattern

Avoid unnecessary re-renders with a context selector pattern that subscribes to specific state slices.

Best for: High-performance global state

#react#context
typescriptadvanced

Suspense Data Fetching Pattern

Use React Suspense for data fetching with resource caching, error boundaries, and streaming SSR.

Best for: Suspense-first data loading

#react#suspense
typescriptadvanced

Context Provider Factory

Utility function that creates a typed React Context with a Provider and a custom hook in one call.

Best for: Creating typed contexts

#context#provider
typescriptadvanced

Server/Client Component Patterns

Correctly compose server and client components with data fetching, interactivity, and composition patterns.

Best for: RSC architecture planning

#nextjs#rsc
typescriptbeginner

Server to Client Component Data Passing

Pass data from server components to client components using props and serialization patterns.

Best for: data hydration

#nextjs#server-components
typescriptintermediate

Server Component Composition Patterns

Compose server and client components effectively with the donut pattern and children pass-through.

Best for: interactive layouts

#nextjs#rsc
sqlintermediate

Common Table Expression (CTE) Patterns

Use CTEs to write readable, composable SQL queries with WITH clauses for complex logic.

Best for: complex queries

#sql#cte
sqlintermediate

Subquery Patterns — Scalar, Correlated, Derived

Common subquery patterns including scalar, correlated, and derived table subqueries.

Best for: complex filtering

#sql#subquery
pythonintermediate

Python Context Manager Patterns

Create custom context managers with __enter__/__exit__ and contextlib for resource management.

Best for: Automatic resource cleanup and lifecycle management

#python#context-manager
pythonintermediate

Python Dataclass Advanced Patterns

Advanced dataclass usage with validation, post-init processing, slots, and frozen instances.

Best for: Type-safe data models without ORMs

#python#dataclass
pythonintermediate

Python Functools and Decorator Patterns

Useful decorator patterns with functools including caching, retry, timing, and rate limiting.

Best for: Adding retry logic to flaky operations

#python#decorators
pythonintermediate

Python Enum Advanced Patterns

Use Python enums with custom values, methods, auto(), and Flag for type-safe constants.

Best for: type-safe constants

#python#enum
kotlinbeginner

Enum Classes — Advanced Patterns

Use Kotlin enum classes with properties, methods, interfaces, and companion utilities.

Best for: Type-safe constant sets with behavior

#kotlin#enum
kotlinadvanced

Custom Property Delegates

Create reusable property delegates: validation, logging, caching, and thread-safe lazy initialization.

Best for: Input validation on property assignment

#kotlin#delegates
kotlinintermediate

Interface Delegation with 'by'

Delegate interface implementations with the 'by' keyword: composition over inheritance patterns.

Best for: Composition over inheritance

#kotlin#delegation
kotlinintermediate

Null Safety — Advanced Patterns

Master null safety in Kotlin: chaining, smart casts, safe builders, orElse patterns, and nullable collections.

Best for: Safe navigation through nested nullable objects

#kotlin#null-safety
kotlinintermediate

Extension Properties and Receiver Functions

Add properties and functions to existing classes: extension receivers, generic extensions, and DSL patterns.

Best for: Adding utility methods to existing types

#kotlin#extensions
kotlinadvanced

Structured Concurrency Patterns

Master coroutine structured concurrency: coroutineScope, async/await, fan-out/fan-in, and parallel map.

Best for: Parallel I/O operations with concurrency limits

#kotlin#coroutines
kotlinadvanced

Type Class Pattern with Generics

Implement type class patterns in Kotlin: ad-hoc polymorphism, generic serializers, and extension-based dispatch.

Best for: Ad-hoc polymorphism without inheritance

#kotlin#generics
kotlinintermediate

Sealed Hierarchies for Domain Modeling

Use sealed interfaces and classes for exhaustive domain modeling with when expressions.

Best for: Payment processing with type-safe methods

#kotlin#sealed
kotlinadvanced

Structured Concurrency Patterns

Apply structured concurrency: parallel decomposition, scoped tasks, cancellation, and resource cleanup.

Best for: Parallel API calls with structured lifecycle

#kotlin#coroutines
kotlinintermediate

Kotlin Error Handling Patterns

Comprehensive error handling: sealed result types, validated aggregation, and railway-oriented programming.

Best for: Form validation with error accumulation

#kotlin#error-handling