
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
@alwatr/fsm
Advanced tools
A robust TypeScript library for implementing Flux (Finite) State Machines, enabling clear and organized management of application state and transitions.
A robust TypeScript library for implementing Flux (Finite) State Machines, enabling clear and organized management of application state and transitions.
@alwatr/observable
for reactive state updates.npm install @alwatr/fsm
import {FluxStateMachineBase} from '@alwatr/fsm';
// Define your states and events
type MyState = 'idle' | 'loading' | 'success' | 'error';
type MyEvent = 'fetch' | 'success' | 'error';
class MyStateMachine extends FluxStateMachineBase<MyState, MyEvent> {
constructor() {
super({
name: 'my-state-machine',
initialState: 'idle',
});
// Define state transitions
this.stateRecord_ = {
idle: {
fetch: 'loading',
},
loading: {
success: 'success',
error: 'error',
},
success: {}, // Terminal state
error: {}, // Terminal state
};
// Define actions (optional)
this.actionRecord_ = {
'_on_fetch': this.handleFetch,
'_on_success': this.handleSuccess,
'_on_error': this.handleError,
};
}
// ... (Implement your action methods: handleFetch, handleSuccess, handleError)
// Trigger a state transition
fetchData() {
this.transition_('fetch');
}
}
FluxStateMachineBase<S extends string, E extends string>
constructor(config: {name: string; loggerPrefix?: string; initialState: S})
:
config.name
: The name of the state machine (used for logging).config.loggerPrefix
: Optional prefix for log messages.config.initialState
: The initial state of the machine.stateRecord_: StateRecord<S, E>
: Defines the states and their possible transitions based on events.
actionRecord_: ActionRecord<S, E>
: Binds action names to class methods for execution during transitions.
transition_(event: E)
: Triggers a state transition based on the provided event.
shouldTransition_(_eventDetail: StateEventDetail<S, E>): MaybePromise<boolean>
: (Optional) Allows you to define custom conditions for transitions.
postTransition__(eventDetail: StateEventDetail<S, E>)
: Executes actions associated with state transitions and events.
execAction__(name: ActionName<S, E>, eventDetail: StateEventDetail<S, E>)
: Executes a specific action if defined in the actionRecord_
.
resetToInitialState_()
: Resets the machine to its initial state without notifying subscribers.
Contributions are welcome! Please read the contributing guidelines before submitting a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.
FAQs
A robust TypeScript library for implementing Flux (Finite) State Machines, enabling clear and organized management of application state and transitions.
The npm package @alwatr/fsm receives a total of 0 weekly downloads. As such, @alwatr/fsm popularity was classified as not popular.
We found that @alwatr/fsm demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.