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

iguazu

Package Overview
Dependencies
Maintainers
5
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iguazu - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

__tests__/config.spec.js

42

__tests__/connectAsync.spec.jsx

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import React, { Component, Children } from 'react';

@@ -10,2 +26,3 @@ import PropTypes from 'prop-types';

import * as utils from '../src/utils';
import config from '../src/config';

@@ -15,2 +32,6 @@ // Module under test

jest.mock('../src/config', () => ({
stateChangeLimiter: jest.fn(func => func),
}));
describe('connectAsync', () => {

@@ -152,2 +173,23 @@ function reducer(state = { param: 'x', x: 'populated data' }, action) {

describe('stateChangeLimiter', () => {
it('applies a globally provided limiter on redux state change', () => {
const ContainerLimited = connectAsync({
loadDataAsProps,
})(Presentation);
const wrapper = mount(<ContainerLimited />, { context: { store } });
const instance = wrapper.instance();
expect(config.stateChangeLimiter).toHaveBeenCalledWith(instance.onReduxStateChange);
});
it('applies a locally provided limiter on redux state change', () => {
const localStateChangeLimiter = jest.fn(func => func);
const ContainerLimited = connectAsync({
loadDataAsProps,
stateChangeLimiter: localStateChangeLimiter,
})(Presentation);
const wrapper = mount(<ContainerLimited />, { context: { store } });
const instance = wrapper.instance();
expect(localStateChangeLimiter).toHaveBeenCalledWith(instance.onReduxStateChange);
});
});
describe('isLoading', () => {

@@ -154,0 +196,0 @@ it('should be provided as a prop to the wrapped component', () => {

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import {

@@ -6,3 +22,5 @@ connectAsync,

noncritical,
sequence,
enableSSR,
configureIguazu,
} from '../src/index';

@@ -16,4 +34,6 @@

expect(noncritical).toBeDefined();
expect(sequence).toBeDefined();
expect(enableSSR).toBeDefined();
expect(configureIguazu).toBeDefined();
});
});

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import mapValues from 'lodash/mapValues';

@@ -2,0 +18,0 @@

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { enableSSR, resetSSR } from '../src/ssr';

@@ -2,0 +18,0 @@

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import {

@@ -2,0 +18,0 @@ enableSSR,

28

lib/connectAsync.js

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

var _config = require('./config');
var _config2 = _interopRequireDefault(_config);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -54,6 +58,21 @@

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
function connectAsync(_ref) {
var loadDataAsProps = _ref.loadDataAsProps;
var loadDataAsProps = _ref.loadDataAsProps,
localStateChangeLimiter = _ref.stateChangeLimiter;

@@ -123,5 +142,8 @@ var ssrEnabled = loadDataAsProps.ssr;

var store = this.context.store;
var globalStateChangeLimiter = _config2.default.stateChangeLimiter;
var stateChangeLimiter = localStateChangeLimiter || globalStateChangeLimiter;
var onReduxStateChangeLimited = stateChangeLimiter(this.onReduxStateChange);
this.unsubscribe = store.subscribe(function () {
return _this2.mounted && _this2.onReduxStateChange();
return _this2.mounted && onReduxStateChangeLimited();
});

@@ -128,0 +150,0 @@ }

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

});
exports.enableSSR = exports.sequence = exports.noncritical = exports.defer = exports.iguazuReduce = exports.connectAsync = undefined;
exports.configureIguazu = exports.enableSSR = exports.sequence = exports.noncritical = exports.defer = exports.iguazuReduce = exports.connectAsync = undefined;

@@ -21,2 +21,4 @@ var _connectAsync = require('./connectAsync');

var _config = require('./config');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -29,2 +31,17 @@

exports.sequence = _loadHelpers.sequence;
exports.enableSSR = _ssr.enableSSR;
exports.enableSSR = _ssr.enableSSR;
exports.configureIguazu = _config.configureIguazu; /*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

@@ -9,3 +9,17 @@ 'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; /*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

@@ -12,0 +26,0 @@ exports.defer = defer;

@@ -28,3 +28,17 @@ 'use strict';

});
}
} /*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

@@ -31,0 +45,0 @@ function reduceStatus(loadResponseMap) {

@@ -9,2 +9,18 @@ "use strict";

exports.isSSR = isSSR;
/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
var SSR = false;

@@ -11,0 +27,0 @@

@@ -7,2 +7,17 @@ "use strict";

exports.handlePromiseRejection = handlePromiseRejection;
/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

@@ -9,0 +24,0 @@ // eslint-disable-next-line import/prefer-default-export

{
"name": "iguazu",
"version": "2.2.0",
"version": "2.3.0",
"description": "An asynchronous data flow solution for React/Redux applications",
"author": "Maia Teegarden",
"contributors": [
"Nickolas Oliver <nickolas.oliver@aexp.com>",
"Andrew Curtis <andrew.curtis@aexp.com>"
],
"license": "Apache-2.0",

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

@@ -26,3 +26,3 @@ # Iguazu

function MyContainer({ isLoading, loadedWithErrors, myData, myOtherData }) => {
function MyContainer({ isLoading, loadedWithErrors, myData, myOtherData }) {
if (isLoading()) {

@@ -246,6 +246,6 @@ return <div>Loading...</div>

function parentLoadDataAsProps({ store: { dispatch } }) {
const sequenceLoadFunctions = sequence[
const sequenceLoadFunctions = sequence([
{ key: 'parent', handler: () => dispatch(loadLoggedInParent()) },
{ key: 'kids', handler: ({ parent }) => dispatch(loadKidsByParent(parent.id)) }
];
]);

@@ -282,7 +282,7 @@ return {

```javascript
const sequenceLoadFunctions = sequence[
const sequenceLoadFunctions = sequence([
{ key: 'first', handler: () => dispatch(loadFirst()) },
{ key: 'second', handler: ({ first }) => dispatch(loadSecond(first.someParam)) },
{ key: 'third', handler: ({ first, second }) => dispatch(loadThird(first.someParam, second.anotherParam)) }
];
]);
```

@@ -293,3 +293,3 @@

```javascript
const sequenceLoadFunctions = sequence[
const sequenceLoadFunctions = sequence([
{

@@ -305,5 +305,52 @@ key: 'first',

}
];
]);
```
### Limiting
As some functions called within `loadDataAsProps` can be expensive when ran on every Redux state change, you are able to declare a limiter function when calling `connectAsync`. Calls to `loadDataAsProps` are not limited by default.
```javascript
function loadDataAsProps({ store, ownProps }) {
const { dispatch, getState } = store;
return {
myData: () => dispatch(expensiveQueryToData(ownProps.someParam)),
myOtherData: () => dispatch(queryMyOtherData(getState().someOtherParam))
}
}
export default connectAsync({
loadDataAsProps,
stateChangeLimiter: onStateChange => debounce(onStateChange, 100),
})(MyContainer);
```
## Global Configuration
Iguazu is also capable of consuming global configuration that will be applied to all instances of `connectAsync`. These options will be applied unless otherwise overridden by providing the equivalent setting in the `connectAsync` call.
```javascript
import { configureIguazu } from 'iguazu';
configureIguazu({
stateChangeLimiter: onStateChange => debounce(onStateChange, 100), // applied globally.
});
...
function loadDataAsProps({ store, ownProps }) {
const { dispatch, getState } = store;
return {
myData: () => dispatch(expensiveQueryToData(ownProps.someParam)),
myOtherData: () => dispatch(queryMyOtherData(getState().someOtherParam))
}
}
export default connectAsync({
loadDataAsProps,
stateChangeLimiter: onStateChange => debounce(onStateChange, 500), // override global setting.
})(MyContainer);
```
## Why is it called Iguazu?

@@ -328,3 +375,3 @@ This library is all about helping you manage data flow from many different sources. Data flow -> water -> waterfalls -> Iguazu falls - the largest waterfalls system in the world. It could have been named something like react-redux-async, but Iguazu also expects a certain pattern, which means there could potentially be many libraries that follow this pattern that could plug in to Iguazu. A unique name will make them more discoverable. Also it sounds cool.

## Code of Conduct
This project adheres to the [American Express Community Guidelines](https://github.com/americanexpress/iguazu/blob/master/Code-of-Conduct).
This project adheres to the [American Express Community Guidelines](./CODE_OF_CONDUCT.md).
By participating, you are expected to honor these guidelines.

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import React from 'react';

@@ -12,4 +28,8 @@ import hoistStatics from 'hoist-non-react-statics';

import { handlePromiseRejection } from './utils';
import config from './config';
export default function connectAsync({ loadDataAsProps }) {
export default function connectAsync({
loadDataAsProps,
stateChangeLimiter: localStateChangeLimiter,
}) {
const ssrEnabled = loadDataAsProps.ssr;

@@ -61,4 +81,7 @@ function buildState({ store, ownProps, bootstrap }) {

const { store } = this.context;
const { stateChangeLimiter: globalStateChangeLimiter } = config;
const stateChangeLimiter = localStateChangeLimiter || globalStateChangeLimiter;
const onReduxStateChangeLimited = stateChangeLimiter(this.onReduxStateChange);
this.unsubscribe = store.subscribe(
() => (this.mounted && this.onReduxStateChange())
() => (this.mounted && onReduxStateChangeLimited())
);

@@ -65,0 +88,0 @@ }

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import connectAsync from './connectAsync';

@@ -5,2 +21,3 @@ import iguazuReduce from './reduce';

import { defer, noncritical, sequence } from './loadHelpers';
import { configureIguazu } from './config';

@@ -14,2 +31,3 @@ export {

enableSSR,
configureIguazu,
};

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import { isSSR } from './ssr';

@@ -2,0 +18,0 @@

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
import values from 'lodash/values';

@@ -2,0 +18,0 @@ import mapValues from 'lodash/mapValues';

@@ -0,1 +1,17 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
let SSR = false;

@@ -2,0 +18,0 @@

@@ -0,2 +1,18 @@

/*
* Copyright 2017 American Express
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
// eslint-disable-next-line import/prefer-default-export

@@ -3,0 +19,0 @@ export function handlePromiseRejection(promise) {

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