Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Scoped expression evaluation #2564

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/actions/expressions.js
Expand Up @@ -89,6 +89,10 @@ export function deleteExpression(expression: Expression) {
export function evaluateExpressions(frameId: frameIdType) {
return async function({ dispatch, getState, client }: ThunkArgs) {
const expressions = getExpressions(getState()).toJS();
if (!frameId) {
const selectedFrame = getSelectedFrame(getState());
frameId = selectedFrame ? selectedFrame.id : null;
}
for (let expression of expressions) {
await dispatch(evaluateExpression(expression, frameId));
}
Expand Down
25 changes: 21 additions & 4 deletions src/actions/tests/expressions.js
Expand Up @@ -4,7 +4,11 @@ import { actions, selectors, createStore } from "../../utils/test-head";
const mockThreadClient = {
evaluate: (script, { frameId }) => {
return new Promise((resolve, reject) => {
resolve("bla");
if (!frameId) {
resolve("bla");
} else {
resolve("boo");
}
});
}
};
Expand Down Expand Up @@ -45,18 +49,31 @@ describe("expressions", () => {
expect(selectors.getExpression(getState(), "bar").input).to.be("bar");
});

it("should evaluate expressions", async () => {
it("should evaluate expressions global scope", async () => {
const { dispatch, getState } = createStore(mockThreadClient);
const frameId = "baa";

dispatch(actions.addExpression("foo"));
dispatch(actions.addExpression("bar", { visible: false }));

expect(selectors.getExpression(getState(), "foo").value).to.be(null);
expect(selectors.getExpression(getState(), "bar").value).to.be(null);
await dispatch(actions.evaluateExpressions(frameId));
await dispatch(actions.evaluateExpressions());

expect(selectors.getExpression(getState(), "foo").value).to.be("bla");
expect(selectors.getExpression(getState(), "bar").value).to.be("bla");
});

it("should evaluate expressions in specific scope", async () => {
const { dispatch, getState } = createStore(mockThreadClient);

dispatch(actions.addExpression("foo"));
dispatch(actions.addExpression("bar", { visible: false }));

expect(selectors.getExpression(getState(), "foo").value).to.be(null);
expect(selectors.getExpression(getState(), "bar").value).to.be(null);
await dispatch(actions.evaluateExpressions("boo"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this have a frame?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure how i'll mock the frame?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh - i didnt see you were passing frameId in w/ boo. that's good enough for this test :)


expect(selectors.getExpression(getState(), "foo").value).to.be("boo");
expect(selectors.getExpression(getState(), "bar").value).to.be("boo");
});
});