-
Notifications
You must be signed in to change notification settings - Fork 14
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
State is retained when switching between stories #22
Comments
This behaviour was indeed intentional. The decorator has a cache mechanism to avoid recreating everything all over again. I've made a simple test that works in the mock component story. However, all these examples are very simple. Could you help me with this by doing the same test in your project with your components? Just open the file This will force the root element to be recreated every time. --- Old
+++ New
@@ -33,13 +33,13 @@
const modules = Array.isArray(module) ? module : [module];
const { template, props = {} } = typeof story === "string" ? { template: story } : story;
const key = context.id;
- if (!cache[key] || cache[key].template !== template) {
+ if (true || !cache[key] || cache[key].template !== template) {
const element = document.createElement("div");
// Initialize mocked modules
if (mock && mock.modules) {
mock.modules.forEach((moduleToMock) => {
modules.unshift(angular.module(moduleToMock, []).name); If this works, I can make this behaviour configurable per story. |
That certainly refreshes things, though it also refreshes when I change a knob value. Ideally it would only refresh when you switch between stories. But this still might be useful to have as an option! |
It is possible to avoid that by using the |
So sorry for taking so much time to fix this. I've added a new parameter Please check the examples. There is one story for each possible value. Let me know if it worked for your use case. |
Hi titonobre, thanks for your work on this library. I'm seeing some behavior that I'm not sure if it's intentional or not:
The state of a story is retained when switching to another story and back again. You can see this with the Mock component story. Increase the count to 4, switch to a different story, and switch back -- the count is still 4. So the state is being retained somehow.
It seems that storybook is best suited to be a showcase of stateless components, and angularjs is not completely stateless, but it would be helpful to tear down the root element and do a new
angular.bootstrap()
each time a story loads. From debugging the page, I observed thatangular.bootstrap
was being called at most once per story, per page load.It would be even better if storybook would reload the actual iframe between each story, but apparently that's too expensive of an operation to parse javascript and register postMessage listeners.... storybookjs/storybook#729 (comment)
So my main question is: do you see what I'm seeing, and is there a way to force storybook to refresh? Maybe this library could provide an option to do that? Other library plugins (react native and webcomponents) make use of a
forceRefresh
param to theirrender
functions, but it seems this library is different. I don't know that much about the internals.The text was updated successfully, but these errors were encountered: