-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Vue / Knobs - optimize on force render #4773
Conversation
Codecov Report
@@ Coverage Diff @@
## next #4773 +/- ##
==========================================
- Coverage 35.47% 35.42% -0.05%
==========================================
Files 561 561
Lines 6825 6834 +9
Branches 911 913 +2
==========================================
Hits 2421 2421
- Misses 3928 3935 +7
- Partials 476 478 +2
Continue to review full report at Codecov.
|
app/vue/src/client/preview/render.js
Outdated
lastStory[key] = value; | ||
}); | ||
|
||
lastStory.$forceUpdate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this will be necessary since Vue as observers for all values of component internal states ; but that won't kill performances either for most of the case, so it's ok to leave it if you feel it's safer.
If you are to bind knobs to the internal state, this works completely. That said, examples of addons-knob for React shows that knobs should be bound to component's properties, not internal state. From the official addons-knob repo, you can easily link back to this example (here's a sample of it) :
You can see in this story that the In the example you provided, you bind the knobs to storiesOf('Addon|Knobs', module)
.addDecorator(withKnobs)
.add('Simple', () => {
const name = text('Name', 'John Doe');
const age = number('Age', 44);
return {
components: { SimpleKnobExample },
+ props: ['name', 'age'],
template: '<simple-knob-example :name="name" :age="age" />',
- data() {
- return { name, age };
- },
};
}) Then, to make it work, you only need to render the story with Here's a working example (fully in Vue, but only #L57-62 matters) : http://jsfiddle.net/bn8tvpdL/ It will probably fix the 2nd use case since nothing will be changed and Vue's diffing will do the magic. |
with permission of @igor-dv , i proposed to solve this. What I didFirst i went back to defining the most simple usecase, as it would be in React. Because Vue and React are different, we can't really translate, but what we know is that stories are returning components, and knobs are inserted into properties of those components (for the most part). Then, I've been recoding the render function. The main idea is to keep the root container alive, and use an outside variable to pass props to the component's story. In order not to break HMR, we still need to recreate a new story everytime it refreshes, but only not if Additional notesIt's perfectly ok that the 2nd example destroys/recreate the story every single time. The reason why is normal, is that the template is a full string and is interpreted as such. There's no deep diffing possible within a component when the template string is given in such a way because Vue tries to optimize the template rendering and detects a purely static string. Such an example should not exist because it doesn't translate from React to Vue paradigm. Knobs should remain properties and derivated values should be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed a few minor things. I can't approve since it's my PR
…render Vue / Knobs - optimize on force render
Issue: #4516
What I did
I've added the optimization that should partially address the #4516 problem.
This solves:
In case the knobs are bounded to
data()
function:we can easily extract this data and replace it in the existing story
This doesn't solve
The case where the story returns only template:
I don't know how to force update the existing story with this template without recreating the story 🤷♂️
CC, @y-nk @pksunkara, would like to hear your thoughts if there are other use-cases when we can just update the component and not destroy it.