-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Salaverry
committed
Aug 2, 2019
1 parent
7192c8f
commit 817c7c3
Showing
4 changed files
with
124 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,55 @@ | ||
[![Build Status](https://travis-ci.org/{{github-user-name}}/{{github-app-name}}.svg?branch=master)](https://travis-ci.org/{{github-user-name}}/{{github-app-name}}.svg?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/{{github-user-name}}/{{github-app-name}}/badge.svg?branch=master)](https://coveralls.io/github/{{github-user-name}}/{{github-app-name}}?branch=master) | ||
[![Build Status](https://travis-ci.org/barakplasma/finite-state-machine.svg?branch=master)](https://travis-ci.org/barakplasma/finite-state-machine.svg?branch=master) | ||
[![Coverage Status](https://coveralls.io/repos/github/barakplasma/finite-state-machine/badge.svg?branch=master)](https://coveralls.io/github/barakplasma/finite-state-machine?branch=master) | ||
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) | ||
|
||
# Using this module in other modules | ||
# Finite State Machine | ||
Tiny finite state machine library for fun and profit. | ||
See the tests for more usage examples. | ||
|
||
## Using this module in other modules | ||
|
||
Here is a quick example of how this module can be used in other modules. The [TypeScript Module Resolution Logic](https://www.typescriptlang.org/docs/handbook/module-resolution.html) makes it quite easy. The file `src/index.ts` is a [barrel](https://basarat.gitbooks.io/typescript/content/docs/tips/barrel.html) that re-exports selected exports from other files. The _package.json_ file contains `main` attribute that points to the generated `lib/index.js` file and `typings` attribute that points to the generated `lib/index.d.ts` file. | ||
|
||
> If you are planning to have code in multiple files (which is quite natural for a NodeJS module) that users can import, make sure you update `src/index.ts` file appropriately. | ||
- To use the `FSM` class in a TypeScript file - | ||
|
||
Now assuming you have published this amazing module to _npm_ with the name `my-amazing-lib`, and installed it in the module in which you need it - | ||
```ts | ||
import { FSM } from "@barakplasma/finite-state-machine"; | ||
|
||
- To use the `Greeter` class in a TypeScript file - | ||
const anFSM = new FSM(); | ||
|
||
```ts | ||
import { Greeter } from "my-amazing-lib"; | ||
anFSM.addState('on'); | ||
anFSM.addState('off'); | ||
|
||
anFSM.on({ inputName: 'toggle' }, () => { | ||
return new Map([['on', 'off'], ['off', 'on']]); | ||
}); | ||
|
||
const { dispatch } = anFSM; | ||
|
||
dispatch({ inputName: 'toggle' }); | ||
|
||
const greeter = new Greeter("World!"); | ||
greeter.greet(); | ||
anFSM.getCurrentState() // 'off' | ||
``` | ||
|
||
- To use the `Greeter` class in a JavaScript file - | ||
- To use the `FSM` class in a JavaScript file - | ||
|
||
```js | ||
const Greeter = require('my-amazing-lib').Greeter; | ||
const FSM = require('my-amazing-lib').FSM; | ||
|
||
const anFSM = new FSM(); | ||
|
||
anFSM.addState('on'); | ||
anFSM.addState('off'); | ||
|
||
anFSM.on({ inputName: 'toggle' }, () => { | ||
return new Map([['on', 'off'], ['off', 'on']]); | ||
}); | ||
|
||
const { dispatch } = anFSM; | ||
|
||
dispatch({ inputName: 'toggle' }); | ||
|
||
const greeter = new Greeter('World!'); | ||
greeter.greet(); | ||
anFSM.getCurrentState() // 'off' | ||
``` | ||
|
||
## Setting travis and coveralls badges | ||
1. Sign in to [travis](https://travis-ci.org/) and activate the build for your project. | ||
2. Sign in to [coveralls](https://coveralls.io/) and activate the build for your project. | ||
3. Replace {{github-user-name}}/{{github-app-name}} with your repo details like: "ospatil/generator-node-typescript". | ||
# finite-state-machine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters