Skip to content

Commit

Permalink
Don't show any circular reference errors when getDataElementValues is…
Browse files Browse the repository at this point in the history
… called with a list of data elements that don't have circular references.

This fixes this issue:
adobe/reactor-extension-cloud-connector-edge#5.
  • Loading branch information
dompuiu committed Nov 16, 2023
1 parent 2117c31 commit ceaae0b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/__tests__/createGetDataElementValues.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,17 @@ describe('function returned by createGetDataElementValues', () => {
expect(getDataElementValue).toHaveBeenCalledWith('de1', context);
});
});

test('sends a cloned dataElementCallStack to getDataElementValue', () => {
const getDataElementValues = createGetDataElementValues(
(dataElementName, { dataElementCallStack }) => {
dataElementCallStack.push(dataElementName);

expect(dataElementCallStack).toStrictEqual([dataElementName]);
}
);

const context = {};
return getDataElementValues(['de1', 'de2'], context);
});
});
8 changes: 5 additions & 3 deletions src/createGetDataElementValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

module.exports = (getDataElementValue) => (tokenList, context) =>
Promise.all(
module.exports = (getDataElementValue) => (tokenList, context) => {
const { dataElementCallStack = [] } = context;

return Promise.all(
tokenList.map((t) => {
const { dataElementCallStack = [] } = context;
context.dataElementCallStack = dataElementCallStack.slice();

return getDataElementValue(t, context);
Expand All @@ -26,3 +27,4 @@ module.exports = (getDataElementValue) => (tokenList, context) =>

return (name) => zipResults[name];
});
};

0 comments on commit ceaae0b

Please sign in to comment.