feat: add support for play functions#57
feat: add support for play functions#57tobiasdiez merged 8 commits intotobiasdiez:mainfrom AntarEspadas:play-function
Conversation
tobiasdiez
left a comment
There was a problem hiding this comment.
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
playoption 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>
|
I think that's it |
tobiasdiez
left a comment
There was a problem hiding this comment.
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.