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

Update state modification in pipelines to use immer #1241

Open
snopoke opened this issue Feb 25, 2025 · 0 comments
Open

Update state modification in pipelines to use immer #1241

snopoke opened this issue Feb 25, 2025 · 0 comments

Comments

@snopoke
Copy link
Contributor

snopoke commented Feb 25, 2025

See https://immerjs.github.io/immer/

Example:
https://github.com/dimagi/open-chat-studio/blob/main/assets/javascript/apps/pipeline/nodes/widgets.tsx#L220-L231

function getNewNodeData(old: Node, updatedList: Array<string>) {
    return {
      ...old,
      data: {
        ...old.data,
        params: {
          ...old.data.params,
          [props.name]: updatedList,
        },
      },
    };
  }

Becomes

function getNewNodeData(old: Node, updatedList: Array<string>) {
    return produce(old, new => {
        new.data.params[props.name] = updatedList
    });
  }
@snopoke snopoke converted this from a draft issue Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔖 Ready
Development

No branches or pull requests

1 participant