Comparing version 0.1.0 to 0.5.0
22
index.js
"use strict"; | ||
const fsm = require('FSM'); | ||
const fsm = require('f-s-m'); | ||
const mixin = require('mixin'); | ||
@@ -10,5 +10,5 @@ const EventEmitter = require('events'); | ||
constructor(chainOfEvents) { | ||
constructor(chainOfEvents, options) { | ||
super(); | ||
this.options = options || {}; | ||
this.events = chainOfEvents.split('>')[0]; | ||
@@ -24,3 +24,3 @@ this.reactions = chainOfEvents.split('>')[1]; | ||
this.setupTriggers(); | ||
this.setInitialState('State0'); | ||
this.setInitialState("State0"); | ||
return this; | ||
@@ -50,4 +50,14 @@ } | ||
let reaction = this.reactions[index]; | ||
if (reaction === undefined) return; | ||
if (reaction === undefined) { | ||
if (this.options.resetAfterReactions) { | ||
this.reset(); | ||
} | ||
return | ||
}; | ||
if (this.options.resetBeforeReactions && index === 0) { | ||
this.reset(); | ||
} | ||
setTimeout(() => { | ||
@@ -87,2 +97,2 @@ this.emit('reaction', reaction.event); | ||
module.exports = Reacter; | ||
module.exports = Reacter; |
{ | ||
"name": "reacterjs", | ||
"version": "0.1.0", | ||
"version": "0.5.0", | ||
"description": "A simple Object that can start a chain of reactions after a chain of events", | ||
"main": "index.js", | ||
"dependencies": { | ||
"FSM": "github:lucalanziani/FSM", | ||
"f-s-m": "^1.0.1", | ||
"mixin": "^0.2.0" | ||
@@ -9,0 +9,0 @@ }, |
Reacter | ||
------- | ||
A simple Object that can start a chain of reactions after a chain of events | ||
A simple Object that can start a chain of actions after a chain of events | ||
The user can define the chain of actions/reactions as a simple string with the following format: | ||
The user can define the chain of events/actions as a simple string with the following format: | ||
``` | ||
event1 - event2[;timeout] ... > action1[;timer] - action2[;timer] - action3[;timer] | ||
event1 - event2[;<timeout>ms] ... > action1[;<timer>ms] - action2[;<timer>ms] - action3[;<timer>ms] | ||
``` | ||
**ATTENTION**: both the timeout and the timer should have the `ms` suffix | ||
## Simple rules | ||
1. events and actions are simply strings | ||
2. `-` is used as separator on both events and actions | ||
3. it expects `>` as separator between events and actions | ||
4. it expects `;` as timeout/timer separator | ||
5. both the timeout and the timer should have the `ms` suffix | ||
6. given the above rules you cannot use `-` and `>` on your events/actions strings | ||
example: | ||
``` | ||
```javascript | ||
const Reacter = require('reacter'); | ||
@@ -18,0 +25,0 @@ let reacter = new Reacter("e1 - e2;30ms > a1 - a2;30ms"); |
@@ -101,1 +101,23 @@ var Reacter = require('../'); | ||
tap.test('Reset after reactions', function (childTest) { | ||
childTest.plan(3); | ||
let reacter = new Reacter('1 - 1;100ms > 1/1/1;0;100ms', {resetAfterReactions: true}).on('reaction', function (event) { | ||
childTest.equal('1/1/1;0', event, 'Reaction!!!'); | ||
}).process('1').process('1'); | ||
childTest.equal(reacter.getCurrentState(), 'State2', 'It did not reset yet'); | ||
setTimeout(function () { | ||
childTest.equal(reacter.getCurrentState(), 'State0', 'Reset Done'); | ||
}, 200); | ||
}); | ||
tap.test('Reset before reactions', function (childTest) { | ||
childTest.plan(2); | ||
let reacter = new Reacter('1 - 1;100ms > 1/1/1;0;200ms', {resetBeforeReactions: true}).on('reaction', function (event) { | ||
childTest.equal('1/1/1;0', event, 'Reaction!!!'); | ||
}).process('1').process('1'); | ||
childTest.equal(reacter.getCurrentState(), 'State0', 'It reset the state before reaction'); | ||
}); | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
9806
202
30
0
+ Addedf-s-m@^1.0.1
+ Addedf-s-m@1.0.1(transitive)
- RemovedFSM@github:lucalanziani/FSM