Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clone history events to prevent mutation #479

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sam-goodwin
Copy link
Owner

No description provided.

Comment on lines +1597 to +1599
e = await mutateEntity.get({
pk: "pk",
});
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: delete to clean up

Comment on lines +2 to +3
// TODO: more efficient deep clone
return item === undefined ? item : JSON.parse(JSON.stringify(item));
Copy link
Contributor

Choose a reason for hiding this comment

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

create issue?

const historyEvents = executor.history.slice(0);
const historyEvents = executor.historyCloned.slice(0);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe just use the cloned one in the executor's iterator and return the original array in .history?

Comment on lines +210 to +220
// clone the history so it cannot be modified by the user
public historyCloned: HistoryStateEvent[];

constructor(
private workflow: Workflow<any, Input, Output>,
public history: HistoryStateEvent[],
// TODO: properties used in the workflow should be encoded in the history to keep them constant between runs
private propertyRetriever: PropertyRetriever,
private eventualFactory: EventualFactory = createDefaultEventualFactory()
) {
this.historyCloned = deepClone(history);
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe use .historyCloned in the iterator in here, leave it private, and then leave the original array in the .history?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants