Skip to content

Commit

Permalink
feat: rename pause prop to paused and watch its effect
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Oct 5, 2020
1 parent ef7c16a commit fca32d4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions packages/villus/src/Subscription.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { defineComponent, SetupContext } from 'vue-demi';
import { defineComponent, watchEffect } from 'vue-demi';
import { normalizeChildren } from './utils';
import { useSubscription, defaultReducer, Reducer } from './useSubscription';
import { DocumentNode } from 'graphql';

export const Subscription = defineComponent({
name: 'Subscription',
Expand All @@ -14,7 +13,7 @@ export const Subscription = defineComponent({
type: Object,
default: null,
},
pause: {
paused: {
type: Boolean,
default: false,
},
Expand All @@ -23,14 +22,26 @@ export const Subscription = defineComponent({
default: undefined,
},
},
setup(props: SubscriptionProps, ctx: SetupContext) {
setup(props, ctx) {
const { data, error, pause, isPaused, resume } = useSubscription(
{
...props,
query: props.query as string,
variables: props.variables as Record<string, any> | undefined,
},
props.reduce || defaultReducer
(props.reduce as Reducer) || defaultReducer
);

watchEffect(() => {
if (props.paused && !isPaused.value) {
pause();
return;
}

if (isPaused.value) {
resume();
}
});

return () => {
return normalizeChildren(ctx, {
data: data.value,
Expand Down
2 changes: 1 addition & 1 deletion packages/villus/test/subscription.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount } from './helpers/mount';
import flushPromises from 'flush-promises';
import { Subscription, createClient, Provider } from '../src/index';
import { Subscription, Provider } from '../src/index';
import { makeObservable, tick } from './helpers/observer';

beforeAll(() => {
Expand Down

0 comments on commit fca32d4

Please sign in to comment.