wirestate is a lightweight, scalable state management library for React, leveraging Inversify for Dependency Injection and MobX for reactivity. It provides a robust architecture for managing complex application logic through Services, Signals, and Queries.
- Dependency Injection: First-class support for Inversify, allowing for decoupled and testable services.
- Reactive State: Seamless integration with MobX.
- Signals: An event-based communication system for broadcasting actions and side effects across your application.
- Queries: A structured way to request data synchronously or asynchronously from your services.
- Service Lifecycle: Automated activation and deactivation of services tied to your component tree.
npm install --save wirestate
react >= 16.8.0mobx >= 6.0.0mobx-react-lite >= 4.0.0inversify >= 8.0.0
import { AbstractService, OnSignal, OnQuery, makeAutoObservable } from 'wirestate';
export class CounterService extends AbstractService {
public count = 0;
constructor() {
super();
makeAutoObservable(this);
}
@OnSignal('INCREMENT')
public increment() {
this.count++;
}
@OnQuery('GET_COUNT')
public getCount() {
return this.count;
}
}import { IocProvider, createInjectablesProvider } from 'wirestate';
import { CounterService } from './CounterService';
const InjectablesProvider = createInjectablesProvider([CounterService]);
function Application() {
return (
<IocProvider>
<InjectablesProvider>
<CounterComponent />
</InjectablesProvider>
</IocProvider>
);
}import { observer } from 'mobx-react-lite';
import { useInjection, useSignalEmitter } from 'wirestate';
import { CounterService } from './CounterService';
const CounterComponent = observer(() => {
const service = useInjection(CounterService);
const emit = useSignalEmitter();
return (
<div>
<p>Count: {service.count}</p>
<button onClick={() => service.increment()}>Increment</button>
<button onClick={() => emit({ type: 'INCREMENT' })}>Increment signal</button>
</div>
);
});Feel free to open PRs or issues.
MIT