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

stent

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stent - npm Package Compare versions

Comparing version 0.0.7 to 0.0.8

lib/react/__tests__/connect.spec.js

23

lib/helpers/__tests__/connect.spec.js

@@ -85,2 +85,25 @@ 'use strict';

});
describe('when we use the `disconnect` function', function () {
it('should detach the mapping', function () {
var mapping = sinon.spy();
var machine = _.Machine.create('A', {
state: { name: 'idle' },
transitions: {
idle: { run: 'running' },
running: { stop: 'idle' }
}
});
var disconnect = (0, _connect2.default)().with('A').map(function (A) {
mapping(A.state.name);
});
machine.run();
disconnect();
machine.stop();
expect(mapping).to.be.calledTwice;
expect(mapping.firstCall).to.be.calledWith(sinon.match('idle'));
expect(mapping.secondCall).to.be.calledWith(sinon.match('running'));
});
});
});

4

lib/helpers/connect.js

@@ -39,2 +39,6 @@ 'use strict';

done.apply(undefined, machines);
return function () {
if (mappings && mappings[id]) delete mappings[id];
};
};

@@ -41,0 +45,0 @@

2

package.json
{
"name": "stent",
"version": "0.0.7",
"version": "0.0.8",
"description": "Stent is a state machines container made for UI development",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -13,3 +13,3 @@ # Stent

* [`<action-handler>`](#action-handler)
* [`connect`](#connect)
* [`connect` and `disconnect`](#connect-and-disconnect)
* [Helpers used inside generators](#helpers-used-inside-generators)

@@ -269,3 +269,3 @@ * [Middlewares](#middlewares)

### `connect`
### `connect` and `disconnect`

@@ -297,5 +297,18 @@ `connect` is the short way to do `Machine.get` and retrieving one or more created machines.

There's also a helper for integration with React. It creates a [HOC](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components):
You may also need to `disconnect` which makes sense if you use the `map` function. If you are connecting with `mapOnce` your mapping function is getting called only once anyway.
```js
const disconnect = connect()
.with('MachineA', 'MachineB')
.mapOnce((MachineA, MachineB) => {
// this gets called only once
});
// at some point later
disconnect();
```
There's also a helper for integrating with React. It creates a [HOC](https://github.com/krasimir/react-in-patterns/tree/master/patterns/higher-order-components):
```js
import React from 'react';

@@ -321,3 +334,3 @@ import { connect } from 'stent/react';

The result of the `map` function goes as props to our component. Similarly to [Redux's connect](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) function.
The result of the `map` function goes as props to our component. Similarly to [Redux's connect](https://github.com/reactjs/react-redux/blob/master/docs/api.md#connectmapstatetoprops-mapdispatchtoprops-mergeprops-options) function. And of course the mapping function is disconnected when the component is unmounted.

@@ -390,3 +403,3 @@ ### Helpers used inside generators

The hooks above are getting called just before running the internal Stent's logic. At this moment nothing in the machine is changing/executing. Calling `next` will pass the control flow to Stent.
The hooks above are getting called just before running the internal Stent's logic. At this moment nothing in the machine is changing/executing. Calling `next` will pass the control flow to Stent. Also have in mind that these methods are fired with the machine as a context. Which means that you have an access to the current state and methods.

@@ -393,0 +406,0 @@ ## Examples

@@ -80,2 +80,25 @@ import connect from '../connect';

});
describe('when we use the `disconnect` function', function () {
it('should detach the mapping', function () {
const mapping = sinon.spy();
const machine = Machine.create('A', {
state: { name: 'idle' },
transitions: {
idle: { run: 'running' },
running: { stop: 'idle' }
}
});
const disconnect = connect().with('A').map(A => {
mapping(A.state.name);
});
machine.run();
disconnect();
machine.stop();
expect(mapping).to.be.calledTwice;
expect(mapping.firstCall).to.be.calledWith(sinon.match('idle'));
expect(mapping.secondCall).to.be.calledWith(sinon.match('running'));
});
});
});

@@ -24,2 +24,6 @@ import { Machine } from '../';

done(...machines);
return () => {
if (mappings && mappings[id]) delete mappings[id];
}
}

@@ -26,0 +30,0 @@

Sorry, the diff of this file is not supported yet

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