Skip to content

Commit

Permalink
fix(vue3): state sync breaking after loading story 2nd time, fix #128
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Jun 22, 2022
1 parent 86e580f commit 58ecf07
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/histoire-plugin-vue/src/client/app/Variant.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineComponent({
const implicitState = inject<() => any>('implicitState')
watch(() => implicitState, value => {
applyStateToVariant(attrs.variant, value())
applyStateToVariant(attrs.variant, value(), true)
}, {
immediate: true,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/histoire-shared/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export function omit (data, keys: string[]) {
return copy
}

export function applyStateToVariant (variant: Variant, state: any) {
export function applyStateToVariant (variant: Variant, state: any, override = false) {
if (variant.state) {
for (const key in state) {
if (variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
if (!override && variant.state[key] && !key.startsWith('_h') && typeof variant.state[key] === 'object' && !Array.isArray(variant.state[key])) {
Object.assign(variant.state[key], state[key])
} else {
variant.state[key] = state[key]
Expand Down

0 comments on commit 58ecf07

Please sign in to comment.