-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
feat: add support for play functions #57
Conversation
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.
Thanks a lot, this looks very nice.
Do you have an idea why its necessary to define the play function in a non-setup tag? Is this an issue with the resolveScript
method in the parser?
Could you please:
- Add the
play
option to the StoryProps (https://github.com/tobiasdiez/storybook-vue-addon/blob/main/src/components.d.ts) - Add the example from https://storybook.js.org/docs/vue/writing-stories/introduction#using-the-play-function to https://github.com/tobiasdiez/storybook-vue-addon/tree/main/examples/vite/src/writing-stories (both in the classical and the new vue-native format)
That would be awesome!
Codecov Report
@@ Coverage Diff @@
## main #57 +/- ##
==========================================
- Coverage 93.41% 93.37% -0.05%
==========================================
Files 3 3
Lines 319 332 +13
Branches 51 56 +5
==========================================
+ Hits 298 310 +12
- Misses 21 22 +1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Alright, I'll add the example and the type declaration in a second. When defining the function in a setup script, this is the code that is generated: import { defineComponent as _defineComponent } from "vue";
const _sfc_main = /*#__PURE__*/ _defineComponent({
setup(__props, { expose }) {
expose();
function playFunction({ canvasElement }: any) {
console.log("playFunction");
}
const __returned__ = { playFunction };
Object.defineProperty(__returned__, "__isScriptSetup", {
enumerable: false,
value: true,
});
return __returned__;
},
});
export default {
//decorators: [ ... ],
parameters: {},
};
function renderPrimary(_ctx, _cache, $props, $setup, $data, $options) {
return "hello";
}
export const Primary = () =>
Object.assign({ render: renderPrimary }, _sfc_main);
Primary.storyName = "Primary";
Primary.play = playFunction;
Primary.parameters = {
docs: { source: { code: `hello` } },
}; As you can see, the play function gets put inside the It might be possible to somehow get the function out of |
Thanks for the explanation. That makes sense. We might think about properly handling script setup in the future (but I'm not sure how much unpacking should be done). For now, I agree that defining play functions in non-setup scripts is okay. |
Fixed typo Co-authored-by: Tobias Diez <code@tobiasdiez.com>
…vue-addon into play-function
I think that's it |
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.
This is a very nice addition, thanks a lot!
Happy to help! This addon is really neat. I'd love to work on more issues when I get the time |
Needed #12 for a project, so I figured I might be able to implement it.
Haven't done any extensive testing, but seems to work so far. Main caveat is that the play function must be defined in a non-setup script function.