-
-
Notifications
You must be signed in to change notification settings - Fork 522
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support effect scope outside of component, fix #1505
- Loading branch information
Showing
10 changed files
with
205 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,21 @@ | ||
<script lang="ts" setup> | ||
import { computed } from 'vue' | ||
import ChannelList from './ChannelList.vue' | ||
import GlobalLoading from './GlobalLoading.vue' | ||
import { useRoute } from 'vue-router' | ||
const route = useRoute() | ||
const displayChannels = computed(() => !route.matched.some(r => r.meta?.layout === 'blank')) | ||
</script> | ||
|
||
<template> | ||
<GlobalLoading /> | ||
<div class="flex h-screen items-stretch bg-gray-100"> | ||
<ChannelList class="w-1/4 border-r border-gray-200" /> | ||
<ChannelList | ||
v-if="displayChannels" | ||
class="w-1/4 border-r border-gray-200" | ||
/> | ||
<router-view class="flex-1 overflow-auto" /> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent } from 'vue' | ||
import ChannelList from './ChannelList.vue' | ||
import GlobalLoading from './GlobalLoading.vue' | ||
export default defineComponent({ | ||
name: 'App', | ||
components: { | ||
ChannelList, | ||
GlobalLoading, | ||
}, | ||
}) | ||
</script> |
43 changes: 43 additions & 0 deletions
43
packages/test-e2e-composable-vue3/src/components/ChannelListPinia.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts" setup> | ||
import { useChannels } from '@/stores/channel' | ||
const channelStore = useChannels() | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-if="channelStore.loading" | ||
class="p-12 text-gray-500" | ||
> | ||
Loading channels... | ||
</div> | ||
|
||
<div | ||
v-else | ||
class="flex flex-col bg-white" | ||
> | ||
<router-link | ||
v-for="channel of channelStore.channels" | ||
:key="channel.id" | ||
v-slot="{ href, navigate, isActive }" | ||
:to="{ | ||
name: 'channel', | ||
params: { | ||
id: channel.id, | ||
}, | ||
}" | ||
custom | ||
> | ||
<a | ||
:href="href" | ||
class="channel-link px-4 py-2 hover:bg-green-100 text-green-700" | ||
:class="{ | ||
'bg-green-200 hover:bg-green-300 text-green-900': isActive, | ||
}" | ||
@click="navigate" | ||
> | ||
# {{ channel.label }} | ||
</a> | ||
</router-link> | ||
</div> | ||
</template> |
51 changes: 51 additions & 0 deletions
51
packages/test-e2e-composable-vue3/src/components/ChannelListPinia2.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<script lang="ts" setup> | ||
import { useChannels } from '@/stores/channel' | ||
import { onBeforeUnmount, ref, watch } from 'vue' | ||
const channels = ref<any[]>([]) | ||
let unwatch: (() => void) | undefined | ||
setTimeout(() => { | ||
const channelStore = useChannels() | ||
unwatch = watch(() => channelStore.channels, (newChannels) => { | ||
channels.value = newChannels | ||
}, { | ||
immediate: true, | ||
}) | ||
}, 0) | ||
onBeforeUnmount(() => { | ||
unwatch?.() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div | ||
v-if="channels" | ||
class="flex flex-col bg-white" | ||
> | ||
<router-link | ||
v-for="channel of channels" | ||
:key="channel.id" | ||
v-slot="{ href, navigate, isActive }" | ||
:to="{ | ||
name: 'channel', | ||
params: { | ||
id: channel.id, | ||
}, | ||
}" | ||
custom | ||
> | ||
<a | ||
:href="href" | ||
class="channel-link px-4 py-2 hover:bg-green-100 text-green-700" | ||
:class="{ | ||
'bg-green-200 hover:bg-green-300 text-green-900': isActive, | ||
}" | ||
@click="navigate" | ||
> | ||
# {{ channel.label }} | ||
</a> | ||
</router-link> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
import { createApp, h, provide } from 'vue' | ||
import { createApp } from 'vue' | ||
import { DefaultApolloClient } from '@vue/apollo-composable' | ||
import { createPinia } from 'pinia' | ||
import { apolloClient } from './apollo' | ||
import App from './components/App.vue' | ||
import { router } from './router' | ||
import '@/assets/styles/tailwind.css' | ||
|
||
const app = createApp({ | ||
setup () { | ||
provide(DefaultApolloClient, apolloClient) | ||
}, | ||
render: () => h(App), | ||
}) | ||
const app = createApp(App) | ||
app.use(createPinia()) | ||
app.use(router) | ||
app.provide(DefaultApolloClient, apolloClient) | ||
app.mount('#app') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import gql from 'graphql-tag' | ||
import { useQuery } from '@vue/apollo-composable' | ||
import { defineStore } from 'pinia' | ||
import { computed, watch } from 'vue' | ||
|
||
interface Channel { | ||
id: string | ||
label: string | ||
} | ||
|
||
export const useChannels = defineStore('channel', () => { | ||
const query = useQuery<{ channels: Channel[] }>(gql` | ||
query channels { | ||
channels { | ||
id | ||
label | ||
} | ||
} | ||
`) | ||
|
||
const channels = computed(() => query.result.value?.channels ?? []) | ||
|
||
watch(query.loading, value => { | ||
console.log('loading', value) | ||
}, { | ||
immediate: true, | ||
}) | ||
|
||
return { | ||
loading: query.loading, | ||
channels, | ||
} | ||
}) |
19 changes: 19 additions & 0 deletions
19
packages/test-e2e-composable-vue3/tests/e2e/specs/pinia.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('Pinia', () => { | ||
beforeEach(() => { | ||
cy.task('db:reset') | ||
}) | ||
|
||
it('with current instance', () => { | ||
cy.visit('/pinia') | ||
cy.get('.channel-link').should('have.lengthOf', 2) | ||
cy.contains('.channel-link', '# General') | ||
cy.contains('.channel-link', '# Random') | ||
}) | ||
|
||
it('with effect scope only', () => { | ||
cy.visit('/pinia2') | ||
cy.get('.channel-link').should('have.lengthOf', 2) | ||
cy.contains('.channel-link', '# General') | ||
cy.contains('.channel-link', '# Random') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.