Skip to content

Latest commit

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

About hapi-xstate-plugin

A Hapi xState plugin. Compatible with Hapi 18 and xState 4.6.0.

Build Status

Install

npm install hapi-xstate-plugin --save

Usage

'use strict';constHapi=require('@hapi/hapi');constserver=newHapi.Server({host: localhost,port: 3000});conststartup=async()=>{awaitserver.register([{plugin: require('hapi-xstate-plugin'),options: {initial: 'inactive',states: {inactive: {on: {TOGGLE: 'active'}},active: {on: {TOGGLE: 'inactive'}}}}}]);awaitserver.start();};startup().catch((err)=>{throwerr;});console.log(`${newDate()}: server running at ${server.info.uri}`);

To change state, the xState interpreter is available from within Hapi's server.app object:

constxStateInterpreter=server.app.xStateInterpreter;xStateInterpreter.onTransition((state)=>console.log(state.value));xStateInterpreter.send('TOGGLE');

About

An xState plugin for Hapi version 18

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages