New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

async-connect

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-connect - npm Package Compare versions

Comparing version 0.0.9 to 1.0.0

dist/actions/error.js

10

dist/asyncConnect.js

@@ -17,4 +17,2 @@ 'use strict';

var _propTypes2 = _interopRequireDefault(_propTypes);
var _lib = require('./lib');

@@ -32,4 +30,4 @@

return function (Component) {
var AsyncConnect = function (_React$PureComponent) {
_inherits(AsyncConnect, _React$PureComponent);
var AsyncConnect = function (_React$Component) {
_inherits(AsyncConnect, _React$Component);

@@ -65,6 +63,6 @@ function AsyncConnect() {

return AsyncConnect;
}(_react2.default.PureComponent);
}(_react2.default.Component);
AsyncConnect.contextTypes = {
store: _propTypes2.default.object.isRequired
store: _propTypes.object.isRequired
};

@@ -71,0 +69,0 @@

16

dist/lib/getDeps.js

@@ -11,3 +11,3 @@ 'use strict';

if (!props.store) {
throw new Error('asyncConnect requires a redux store');
throw new Error('async-connect requires a redux store');
}

@@ -19,18 +19,14 @@

if (!Array.isArray(deps)) {
throw new Error('asyncConnect requires an array of dependencies passed to it. See docs.');
throw new Error('async-connect requires an array of actions.');
}
if (!state.async || !state.async.statuses) {
throw new Error('asyncConnect requires async module setup in redux state. See docs.');
throw new Error('async-connect requires an async reducer.');
}
deps.forEach(function (_ref) {
var key = _ref.key,
promise = _ref.promise,
payload = _ref.payload;
if (!state.async.statuses[key]) {
props.store.dispatch(promise(payload));
deps.forEach(function (dep) {
if (!state.async.statuses[dep.type]) {
props.store.dispatch(dep.action(dep.payload));
}
});
};
{
"name": "async-connect",
"description": "redux-async-connect / redux-connect for react-router v4.0.x",
"version": "0.0.9",
"description": "HOC for calling and statusing redux actions on componentDidMount",
"version": "1.0.0",
"author": "bentatum <bentatum@me.com>",

@@ -45,3 +45,4 @@ "bugs": {

"build": "babel -d dist/ src/",
"prepublish": "yarn lint && yarn test && npm run build",
"prebuild": "yarn lint && yarn test",
"prepublish": "npm run build",
"lint": "standard src/",

@@ -48,0 +49,0 @@ "test": "jest test/"

@@ -23,19 +23,29 @@ # async-conncect

```js
import { compose } from 'recompact'
import asyncConnect from 'async-conncect'
import { connect } from 'react-redux'
const enhance = compose(
asyncConnect([{
key: 'getUser',
promise() {
return client.get('user', { id: 'xyz' })
// this will call getUser and getOtherThing on componentDidMount as long as it's corresponding status isnt pending, success or failure.
asyncConnect([
{
type: '@@my-app/getUser',
action: getUser,
payload: {
id: 123
}
},
{
type: '@@my-app/getOtherThing',
action: getOtherThing,
payload: {
id: 456
}
}
}]),
]),
// you'll need to map the response of your action, thunk, saga (er, whatever) in your app's state reducer.
connect(({ user }) => ({ user }))
)
export default enhance(props =>
<div>
{props.user.name}
</div>
)
export default enhance(props => props.user.name

@@ -42,0 +52,0 @@ ```

import React from 'react'
import PropTypes from 'prop-types'
import { object } from 'prop-types'
import { getDeps } from './lib'
export default depsMapper => Component => {
class AsyncConnect extends React.PureComponent {
class AsyncConnect extends React.Component {
componentDidMount () {

@@ -28,3 +28,3 @@ this._getDeps(this.props)

AsyncConnect.contextTypes = {
store: PropTypes.object.isRequired
store: object.isRequired
}

@@ -31,0 +31,0 @@

export default (depsMapper, props = {}) => {
if (!props.store) {
throw new Error('asyncConnect requires a redux store')
throw new Error('async-connect requires a redux store')
}

@@ -11,14 +11,14 @@

if (!Array.isArray(deps)) {
throw new Error('asyncConnect requires an array of dependencies passed to it. See docs.')
throw new Error('async-connect requires an array of actions.')
}
if (!state.async || !state.async.statuses) {
throw new Error('asyncConnect requires async module setup in redux state. See docs.')
throw new Error('async-connect requires an async reducer.')
}
deps.forEach(({ key, promise, payload }) => {
if (!state.async.statuses[key]) {
props.store.dispatch(promise(payload))
deps.forEach(dep => {
if (!state.async.statuses[dep.type]) {
props.store.dispatch(dep.action(dep.payload))
}
})
}
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