hapi-xstate-plugin

4.6.0 • Public • Published

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';
 
const Hapi = require('@hapi/hapi');
 
const server = new Hapi.Server({
    host: localhost,
    port: 3000
});
 
const startup = async () => {
    await server.register([{
        plugin: require('hapi-xstate-plugin'),
        options: {
           initial: 'inactive',
           states: {
               inactive: { on: { TOGGLE: 'active' } },
               active: { on: { TOGGLE: 'inactive' } }
           } 
        }
    }]);
    await server.start();
};
 
startup().catch((err) => {
    throw err;
});
 
console.log(`${new Date()}: server running at ${server.info.uri}`);

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

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

Dependents (0)

Package Sidebar

Install

npm i hapi-xstate-plugin

Weekly Downloads

1

Version

4.6.0

License

MIT

Unpacked Size

5.72 kB

Total Files

6

Last publish

Collaborators

  • visualjeff