This directory contains various examples demonstrating the features and capabilities of super.js. Each example is designed to showcase different aspects of the language and common programming patterns.
Demonstrates the type system features including:
- Type aliases
- Interfaces
- Union types
- Optional types
- Function types
- Array types
Shows object-oriented programming features:
- Class inheritance
- Abstract classes
- Interfaces
- Private fields (#)
- Protected members
- Static methods
Illustrates generic programming concepts:
- Generic interfaces
- Generic classes
- Generic functions
- Type constraints
- Generic type inference
Demonstrates asynchronous iteration:
- Async iterators
- Async generators
- Pagination handling
- Data streaming
Shows the decorator pattern implementation:
- Method decorators
- Class decorators
- Property decorators
- Decorator factories
- Real-world decorator use cases
Implements a dependency injection container:
- Service interfaces
- Service implementations
- Dependency container
- Service registration and resolution
- Application composition
Shows event handling and pub/sub pattern:
- Event emitter implementation
- Event subscription
- Event unsubscription
- Type-safe events
- Real-time updates
Demonstrates state management pattern:
- Action types
- State reducer
- Store implementation
- State subscription
- Immutable updates
Implements the observer pattern:
- Observable class
- Observer interface
- Subscription management
- Real-time data updates
- Multiple observers
Shows middleware pattern implementation:
- Middleware chain
- Request/Response handling
- Async middleware
- Error handling
- Common middleware examples
To run any example, use the super.js compiler:
npx super-js compile examples/path/to/example.sjs
node examples/path/to/example.jsEach example is self-contained and includes a main() function that demonstrates its usage.
For best learning experience, we recommend following the examples in this order:
- Start with basic examples to understand the type system and classes
- Move to advanced examples to learn about generics and async programming
- Explore the design patterns to see how super.js can be used in real-world scenarios
Feel free to add more examples or improve existing ones. Make sure to:
- Follow the established directory structure
- Include detailed comments explaining the code
- Add usage examples in the main function
- Update this README with any new examples