-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Shallow merge top-level object parameters #9219
Comments
// The base
backgrounds: [
{ name: "white", value: "#ffffff", default: true },
{ name: "black", value: "#000000" }
];
// Overide
backgrounds: [{ name: "black", value: "#000000", default: true }]; Since the new entry is not equal to any of the entries in the original array, it would just get appended to the end instead of de-dup the We could special-case How about accepting functions as parameter values? // Overide
backgrounds: originalArray => {
const newArray = originalArray.map(item => ({ ...item }));
// do something with newArray
return newArray;
}; This way, we could provide maximum flexibility without having to do some complicated merging algos. We could still provide the default merging algo if the value is not a function. The downside of this is that if the parameter itself accepts a function then we would have to make it into higher-order functions, I wonder if that's case for any addons now? |
This proposal is pretty limited and I would say uncontroversial (how often are people calling
I don't think so:
storybook/lib/client-api/src/client_api.ts Lines 243 to 261 in a1a1cdd
But it doesn't help in this case where the I suspect a better solution to the larger problem might be to have both context = {
unmergedParameters: {
global: { backgrounds: {...} },
component: { backgrounds: {...} },
story: { backgrounds: {...} },
}
} We could even make global an array to reflect the fact that it can be called more than once (in CSF the others cannot). That way an addon can look at Funnily enough we ran into this exact problem with Chromatic a day or two ago: chromaui/chromatic-cli#80 (cc @kylesuss) |
Note that the larger change would also make sense to only pass global parameters over the channel once, rather once than per-story (and similar with component parameters). |
@tmeasday @kevin940726 Ok I didn't realize we were already applying As for backgrounds, I guess it's unrelated, so I posted separately there: #9164 (comment) |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Duplicate #7872 |
Currently, the
options
anddocs
parameters are shallow merged. I propose applying this behavior for all object parameters, as a breaking change in Storybook 6.0.Here's the reference code: https://github.com/storybookjs/storybook/blob/next/lib/client-api/src/client_api.ts#L93-L105
Motivation
The motivation for this is purely ergonomic.
In
addon-docs
, we set some configurations in the preset, and then users can add/override configurations on a per-story basis.Applying this behavior to all object parameters would mean we don't have to special-case
docs
inside core. It would also be useful in other cases, like making it easy to set the default background on a per-story basis: #9164cc @ndelangen @tmeasday
The text was updated successfully, but these errors were encountered: