Files
webstudio/app/shared/props-utils/update-props.ts
T

26 lines
695 B
TypeScript

import { type AllUserProps, type UserPropsUpdates } from "@webstudio-is/sdk";
export const updateAllUserPropsMutable = (
allUserProps: AllUserProps,
{ instanceId, propsId, treeId, updates }: UserPropsUpdates
) => {
if (instanceId in allUserProps === false) {
allUserProps[instanceId] = {
id: propsId,
instanceId,
treeId,
props: [],
};
}
const instanceProps = allUserProps[instanceId];
for (const update of updates) {
const prop = instanceProps.props.find(({ id }) => id === update.id);
if (prop === undefined) {
instanceProps.props.push(update);
} else {
prop.prop = update.prop;
prop.value = update.value;
}
}
};