New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

state-mechanic

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

state-mechanic

A state machine that tracks and validates state, allows for hide/show logic and can run an action when a state is entered.

latest
Source
npmnpm
Version
1.2.45
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

state-mechanic

And another state machine

Install

npm install state-mechanic

Usage


import {StateConfig} from '../StateMachine/model';
import {StateMechanic} from '../StateMachine/stateMechanics';
import assert from 'assert';

export interface CreateListingModel {
    type?: 'singleCard' | 'mixedBundle' | 'sealedSingle';
}

export const config: StateConfig<CreateListingModel> = {
    type: {
        name: 'Create Listing',
        url: '/createListing/listing-type',
        state: {
            singleCard: {
                name: 'Single Card',
                url: '/createListing/single-card',
                validate: (model: CreateListingModel) => {
                    return model.type === 'singleCard';
                },
            },
            mixedBundle: {
                name: 'Mixed Bundle',
                url: '/createListing/mixed-bundle',
                state: {
                    title: {
                        name: 'Title',
                        url: '/createListing/mixed-bundle/title',
                        hide: (model?: CreateListingModel) => {
                            return ['singleCard', 'mixedBundle'].includes(model?.type);
                        },
                    },
                    tagSelection: {
                        name: 'Tag Selection',
                        url: '/createListing/mixec-bundle/tag-selection',
                        hide: (model?: CreateListingModel) => {
                            return ['singleCard', 'mixedBundle'].includes(model?.type);
                        },
                    },
                },
            },
            sealedSingle: {
                name: 'Sealed Single',
                url: '/createListing/sealed-single',
            },
        },
    },
};


const instance = new StateMechanic(config);
let state = instance.state.type;

state = state.next();
assert(state.name === 'Single Card', "should be single Card");
state = state.next();
assert(state.name === 'Mixed Bundle');
state = state.next();
assert(state.name === 'Title');
expect(1).toBe(1);


Keywords

state-mechanic

FAQs

Package last updated on 27 Oct 2023

Did you know?

Socket

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.

Install

Related posts