Skip to content

Commit

Permalink
Add a warning when there can be undefined behavior
Browse files Browse the repository at this point in the history
Fixes #467
  • Loading branch information
tgolen committed Sep 11, 2020
1 parent 8814c20 commit fa99401
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib/Ion.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,13 @@ function connect(mapping) {
return;
}

// Currently, if a callback or react component is subscribing to a regex key
// and multiple keys match that regex,
// a data change will be published to the callback or react component for EACH
// matching key. In the future, this should be refactored so that identical
// React components or callbacks should only have a single data change published
// to them.
if (matchingKeys.length > 1 && config.withIonInstance && !config.indexBy) {
// eslint-disable-next-line no-console
console.warning(`It looks like a React component subscribed to multiple Ion keys without
providing an 'indexBy' option. This will result in undefined behavior. The best thing to do is
provide an 'indexBy' value, or use a more specific regex that will only match a single Ion key.`);
}

if (config.indexBy) {
Promise.all(_.map(matchingKeys, key => get(key)))
.then(values => _.reduce(values, (finalObject, value) => ({
Expand Down

0 comments on commit fa99401

Please sign in to comment.