1.2.45 • Published 7 months ago

state-mechanic v1.2.45

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

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);
1.2.45

7 months ago

1.2.44

7 months ago

1.2.43

10 months ago

1.2.42

10 months ago

1.2.41

10 months ago

1.2.40

10 months ago

1.2.39

10 months ago

1.2.38

10 months ago

1.2.37

11 months ago

1.2.34

11 months ago

1.2.33

11 months ago

1.2.32

11 months ago

1.2.31

11 months ago

1.2.30

11 months ago

1.2.29

11 months ago

1.2.28

11 months ago

1.2.27

11 months ago

1.2.26

11 months ago

1.2.25

11 months ago

1.2.23

11 months ago

1.2.22

11 months ago

1.2.21

11 months ago

1.2.19

11 months ago

1.2.18

11 months ago

1.2.17

11 months ago

1.2.16

11 months ago

1.2.15

11 months ago

1.2.14

11 months ago

1.2.12

11 months ago

1.2.11

11 months ago

1.2.10

11 months ago

1.2.9

11 months ago

1.2.7

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.2.2

11 months ago

1.2.1

11 months ago

1.2.0

11 months ago

1.1.0

11 months ago

1.0.57

11 months ago

1.0.56

11 months ago

1.0.55

11 months ago

1.0.54

11 months ago

1.0.53

11 months ago

1.0.52

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago