Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

reacterjs

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reacterjs - npm Package Compare versions

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');
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc