@bemobile/fusion-builder
v5.2.9
Published
BE-Mobile
Downloads
27
Readme
BE-Mobile Fusion Builder
Javascript Utility library to conveniently build output for BE-Mobile Fusion.
Installation
Add the package to the project
npm install @bemobile/fusion-builder
Usage
We recommend using the node-server, which provides a ready-to-use framework for building a NodeJS fusion server. But the fusion builder can be used without it:
Standalone
You can create a valid JSON and output it whichever way you like:
import { FusionBuilder, SoundType } from '@bemobile/fusion-builder';
const fusion = new FusionBuilder();
const page = fusion.addPage('Homepage').setTitle('Homepage');
page.addLabel('Home', 'h2').placeElement();
page.addButon('OK')
.onClick()
.messageDialog('You clicked OK')
.onComplete()
.playSound(SoundType.ERROR);
Express
import * as express from 'express';
import * as bodyParser from 'body-parser';
import { Input, SoundType, FusionBuilder } from '@bemobile/fusion-builder';
type FusionRequest = express.Request & { fusion: FusionBuilder };
const app = express();
app.use(bodyParser.json());
app.use((req: FusionRequest) => {
req.fusion = new FusionBuilder(new Input(req.body));
});
app.post('/', (req: FusionRequest, res) => {
req.fusion.setGlobalParameter('test', 'foobar');
const page = req.fusion.addPage('Homepage').setTitle('Homepage');
page.addLabel('Home', 'h2').placeElement();
page.addButon('OK')
.onClick()
.messageDialog('You clicked OK')
.onComplete()
.playSound(SoundType.ERROR);
res.json(req.fusion.getJsonState());
});
app.post('/post2', (req: FusionRequest, res) => {
const page = req.fusion.addPage('Homepage').setTitle('Homepage');
page.addLabel('Home', 'h2').placeElement();
page.addButon('OK')
.onClick()
.messageDialog('You clicked OK')
.onComplete()
.playSound(SoundType.ERROR);
res.json(req.fusion.getJsonState());
});