Giter Site home page Giter Site logo

Comments (6)

sunwukonga avatar sunwukonga commented on June 18, 2024

Actually, for some reason, I cannot get either of

import { Machine, make } from jssm;

or

var jssm = require('jssm');

to work. Machine, make, and jssm respectively are undefined.

from jssm.

sunwukonga avatar sunwukonga commented on June 18, 2024

Even with:

import * as jssm from 'jssm';
console.log(jssm);  // { default: {} }

from jssm.

sunwukonga avatar sunwukonga commented on June 18, 2024

I've used the interactive demo at jssm/src/demo/index.html and manipulated a SM through the console. Yet, I still don't see how to use this library in NodeJS.

from jssm.

sunwukonga avatar sunwukonga commented on June 18, 2024

I've looked at the tests in src/js/tests and the import in those files is:

const jssm = require('../../../build/jssm.es5.js'),
         sm   = jssm.sm;

and obviously works, but this file is not available in the NPM package, and I've used:

const jssm = require('./node_modules/jssm/dist/jssm.es5.cjs.js'),
         sm   = jssm.sm;

as a substitute, but no cookie.The complaint being that sm is not a function, which it is not, it's a property.

from jssm.

sunwukonga avatar sunwukonga commented on June 18, 2024

Tried this again this weekend, and managed to get it working in NodeJS. Seems a bit hacky, but I can now turn a DSL into a fsm.

Install for the project:
npm -i jssm --save

Go to the jssm directory in node_modules:
cd node_modules/jssm

Install dependencies of jssm:
npm install

Then run the make script:
npm run-script make

Now we have a build directory with the file jssm.es5.js and we can import the appropriate functions (or at least I can because I'm using babel to translate imports, otherwise you'd use a require):
import { sm, Machine, make } from './node_modules/jssm/build/jssm.es5';

We can then do something like this:

import fs from 'fs';
fs.readFile('./my.fsl', 'utf8', function(err, planString) {
  let myExampleFSM = new Machine( make( planString ) );
  console.log(myExampleFSM.state());  // check initial state
  myExampleFSM.action('proceed');  // assuming your fsl has a 'proceed' transition
  console.log(myExampleFSM.state());  // check the result of the action
}

Note that the shorter way:
let myExampleFSM = sm( planString );
doesn't work for me because there's an error TypeError: template_strings.reduce is not a functionin return new Machine(make(template_strings.reduce(...

from jssm.

sunwukonga avatar sunwukonga commented on June 18, 2024

The reason why sm( planString ) isn't working for me is because I was trying to pass in a String when it's expecting an array of Strings. Whatever, sm is aiming to achieve with arguments (currently a commented out arg into the sm function), I don't need it. new Machine( make( myDSL_string ) ) works fine.

from jssm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.