Skip to content
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

fix(vue): don't spread in ais-state-results #6481

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions packages/vue-instantsearch/src/components/StateResults.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div :class="suit()" v-if="state && state.state && state.results">
<slot v-bind="stateResults">
<slot v-bind="state">
<p>
Use this component to have a different layout based on a certain state.
</p>
Expand Down Expand Up @@ -38,7 +38,6 @@ export default {
const helper = this.getParentIndex().getHelper();
const state = helper ? helper.state : null;

// @MAJOR no longer spread this inside `results`
this.state = {
results,
state,
Expand Down Expand Up @@ -74,17 +73,5 @@ export default {
},
},
},
computed: {
stateResults() {
const { results, state, status, error } = this.state;
return {
...results,
results,
state,
status,
error,
};
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ it('gives state & results to default slot', () => {
mount(StateResults, {
scopedSlots: {
default: (props) => {
expect(props).toEqual(expect.objectContaining(results));
expect(props.results).toEqual(results);
expect(props.state).toEqual(state);
expect(props.status).toEqual('idle');
Expand Down Expand Up @@ -182,77 +181,3 @@ it('allows default slot to render whatever they want (falsy query)', () => {
</div>
`);
});

describe('legacy spread props', () => {
it('allows default slot to render whatever they want (truthy query)', () => {
__setIndexResults({
query: 'q',
hits: [
{ objectID: '1', name: 'one' },
{ objectID: '2', name: 'two' },
],
page: 1,
});
__setIndexHelper({ state: {} });

const wrapper = mount({
components: { StateResults },
template: `
<StateResults>
<template v-slot="{ query }">
<p v-if="query">
Query is here
</p>
<p v-else>
There's no query
</p>
</template>
</StateResults>
`,
});

expect(wrapper.html()).toMatchInlineSnapshot(`
<div class="ais-StateResults">
<p>
Query is here
</p>
</div>
`);
});

it('allows default slot to render whatever they want (falsy query)', () => {
__setIndexResults({
query: '',
hits: [
{ objectID: '1', name: 'one' },
{ objectID: '2', name: 'two' },
],
page: 1,
});
__setIndexHelper({ state: {} });

const wrapper = mount({
components: { StateResults },
template: `
<StateResults>
<template v-slot="{ query }">
<p v-if="query">
Query is here
</p>
<p v-else>
There's no query
</p>
</template>
</StateResults>
`,
});

expect(wrapper.html()).toMatchInlineSnapshot(`
<div class="ais-StateResults">
<p>
There's no query
</p>
</div>
`);
});
});
37 changes: 0 additions & 37 deletions packages/vue-instantsearch/src/connectors/connectStateResults.js

This file was deleted.

123 changes: 0 additions & 123 deletions packages/vue-instantsearch/src/connectors/connectStateResults.test.js

This file was deleted.

Loading