A modern, type-safe state management library for JavaScript applications.
- 🎯 Type-safe: Built with TypeScript for robust type checking
- 🔄 Computed Values: Automatic dependency tracking and caching
- 🔌 Middleware System: Flexible middleware with dependency management
- ⏱️ Time Travel: Debug your application state with time-travel capabilities
- 🛠️ DevTools: Integration with Redux DevTools
- 💾 Persistence: Built-in state persistence
- 🔄 Async Support: First-class support for async actions
- 🎨 Framework Agnostic: Use with any JavaScript framework
# Not yet published to npm
# Clone the repository
git clone https://github.com/ersinkoc/hafiza.git
cd hafiza
# Install dependencies
npm installimport { createStore } from 'hafiza';
import { logger } from 'hafiza/middleware';
import { computed } from 'hafiza/core';
// Create a store with initial state
const store = createStore({
state: {
todos: [],
filter: 'all'
},
middleware: [logger]
});
// Create computed values with automatic dependency tracking
const filteredTodos = computed((state) => {
switch (state.filter) {
case 'completed':
return state.todos.filter(todo => todo.completed);
case 'active':
return state.todos.filter(todo => !todo.completed);
default:
return state.todos;
}
});
// Subscribe to state changes
store.subscribe((state) => {
console.log('New state:', state);
console.log('Filtered todos:', filteredTodos(state));
});
// Dispatch actions
store.dispatch({
type: 'ADD_TODO',
payload: { id: 1, text: 'Learn Hafiza', completed: false }
});- State Management Best Practices
- Using Middleware
- Working with Computed Values
- Time Travel Debugging
- DevTools Integration
- State Persistence
- TypeScript Usage
Check out the examples directory for sample applications:
- Todo App: Basic todo application demonstrating core features
- Shopping Cart: E-commerce example with async actions and persistence
- Kanban Board: Complex project management with drag-and-drop
- Chat App: Real-time messaging with user status and typing indicators
- Form Builder: Dynamic form creation with validation and preview
- Counter: Simple counter with basic state management
- Notes: Note-taking app with tags and search
- Timer: Countdown and stopwatch functionality
- Theme Switcher: Dynamic theme management and customization
- Dashboard: Widget-based dashboard with drag-and-drop layout