woofnals
v1.0.0
Published
Lightweight, Akita-inspired state management for Angular Signals
Downloads
4
Maintainers
Readme
woofnals
Lightweight, Akita-inspired state management for Angular Signals.
Installation
Install the library via npm:
npm install woofnalsUsage
Basic Store Usage
import { Store } from 'woofnals';
interface User {
id: number;
name: string;
email: string;
}
// Create a store for User entities
const userStore = new Store<User>();
// Add entities
userStore.add({ id: 1, name: 'John Doe', email: '[email protected]' });
userStore.addMany([
{ id: 2, name: 'Jane Smith', email: '[email protected]' },
{ id: 3, name: 'Bob Johnson', email: '[email protected]' }
]);
// Get all entities
const users = userStore.getAll();
// Update an entity
userStore.update(1, { name: 'John Updated' });
// Remove an entity
userStore.remove(2);Query Usage
import { Query } from 'woofnals';
// Create a query for the store
const userQuery = new Query(userStore);
// Get filtered results
const activeUsers = userQuery.selectAll(user => user.active);
// Get a specific entity
const user = userQuery.selectEntity(1);
// Check if loading
const isLoading = userQuery.selectLoading();EntityStore Usage
import { EntityStore } from 'woofnals';
// EntityStore extends Store with additional query capabilities
const userEntityStore = new EntityStore<User>();
// All Store methods are available
userEntityStore.add({ id: 1, name: 'John', email: '[email protected]' });
// Plus additional query methods
const allUsers = userEntityStore.selectAll();
const specificUser = userEntityStore.selectEntity(1);Requirements
- Angular 17+ (supports Angular 17, 18, 19, and 20)
- TypeScript 4.9+
API Reference
Store
Core store class for managing entities.
Methods
add(entity: T): void- Add a single entityaddMany(entities: T[]): void- Add multiple entitiesremove(id: string | number): void- Remove an entity by IDupdate(id: string | number, changes: Partial<T>): void- Update an entitygetAll(): T[]- Get all entities
Query
Query class for reactive data selection.
Methods
selectAll(filterFn?: (entity: T) => boolean): T[]- Select all entities with optional filterselectEntity(id: string | number): T | undefined- Select a specific entityselectLoading(): boolean- Check loading state
EntityStore
Extended store with built-in query capabilities.
Inherits all methods from Store<T> and Query<T>.
Development
This section is for contributors who want to develop the library itself.
Prerequisites
- Node.js 18+
- npm 9+
Setup
# Clone the repository
git clone <repository-url>
cd woofnals
# Install dependencies
npm installBuilding the library
npm run buildThe built library will be available in the dist/woofnals/ directory.
Running tests
npm run testFor watch mode during development:
npm run test:watchLinting
npm run lintPublishing
To publish a new version:
# Build and publish (dry run first)
npm run publish:dry-run
# Actual publish
npm run releaseProject Structure
woofnals/
├── projects/signals/ # Library source code (named signals for Angular CLI compatibility)
│ ├── src/
│ │ ├── lib/
│ │ │ ├── core/ # Core functionality
│ │ │ │ ├── store.ts
│ │ │ │ ├── query.ts
│ │ │ │ ├── entity-store.ts
│ │ │ │ └── signals.ts
│ │ │ └── __tests__/ # Test files
│ │ └── public-api.ts # Public API exports
│ ├── ng-package.json # Library build configuration
│ ├── package.json # Library package configuration
│ └── jest.config.js # Test configuration
├── dist/ # Build output
├── angular.json # Angular CLI configuration
└── package.json # Workspace dependenciesLicense
MIT
