2017-09-06 13 views
1

Relay Modernのサブスクリプションをどのように退会しますか?Relay Modernの退会方法

私はHow to GraphQL React + Relayのサブスクリプションチュートリアルに従っていますが、どのようにしてRelay Modern Webサイトの購読を解除するかについては言及していません。

ご協力いただければ幸いです。

UPDATEが----------

リー・バイロン(see GitHub issue)によると、先ほどの例に次の変更を行った後requestSubscription()

dispose() を呼び出す必要があります:

./src/subscriptions/NewVoteSubscription.js

return requestSubscriptionへの追加)ここで

./src/components/LinkList.js(コンポーネントにサブスクリプションを設定し、それがdispose()componentWillUnmountを使用して)

componentDidMount() { 
    this.subscription = NewVoteSubscription() 
} 

componentWillUnmount() { 
    this.subscription.dispose() 
} 

は私が取得エラーです:

Uncaught TypeError: Cannot read property 'dispose' of undefined 
    at RelayObservable.js:94 
    at doCleanup (RelayObservable.js:453) 
    at Object.unsubscribe (RelayObservable.js:474) 
    at RelayObservable.js:330 
    at doCleanup (RelayObservable.js:453) 
    at Object.unsubscribe (RelayObservable.js:474) 
    at doCleanup (RelayObservable.js:450) 
    at Object.unsubscribe [as dispose] (RelayObservable.js:474) 
    at LinkList.componentWillUnmount (LinkList.js:18) 
    at callComponentWillUnmountWithTimerInDev (react-dom.development.js:11123) 
    at HTMLUnknownElement.callCallback (react-dom.development.js:1309) 
    at Object.invokeGuardedCallbackDev (react-dom.development.js:1348) 
    at invokeGuardedCallback (react-dom.development.js:1205) 
    at safelyCallComponentWillUnmount (react-dom.development.js:11131) 
    at commitUnmount (react-dom.development.js:11421) 
    at unmountHostComponents (react-dom.development.js:11362) 
    at commitDeletion (react-dom.development.js:11392) 
    at commitAllHostEffects (react-dom.development.js:12279) 
    at HTMLUnknownElement.callCallback (react-dom.development.js:1309) 
    at Object.invokeGuardedCallbackDev (react-dom.development.js:1348) 
    at invokeGuardedCallback (react-dom.development.js:1205) 
    at commitAllWork (react-dom.development.js:12384) 
    at workLoop (react-dom.development.js:12695) 
    at HTMLUnknownElement.callCallback (react-dom.development.js:1309) 
    at Object.invokeGuardedCallbackDev (react-dom.development.js:1348) 
    at invokeGuardedCallback (react-dom.development.js:1205) 
    at performWork (react-dom.development.js:12808) 
    at batchedUpdates (react-dom.development.js:13262) 
    at performFiberBatchedUpdates (react-dom.development.js:1656) 
    at stackBatchedUpdates (react-dom.development.js:1647) 
    at batchedUpdates (react-dom.development.js:1661) 
    at Object.batchedUpdatesWithControlledComponents [as batchedUpdates] (react-dom.development.js:1674) 
    at dispatchEvent (react-dom.development.js:1884) 

答えて

3

とセットアップリレー環境

function setupSubscription(config, variables, cacheConfig, observer) { 
    const query = config.text; 

    const subscriptionClient = new SubscriptionClient(websocketURL, { 
    reconnect: true 
    }); 

    const client = subscriptionClient.request({ query, variables }).subscribe({ 
    next: result => { 
     observer.onNext({ data: result.data }); 
    }, 
    complete:() => { 
     observer.onCompleted(); 
    }, 
    error: error => { 
     observer.onError(error); 
    } 
    }); 

    return { 
    dispose: client.unsubscribe 
    }; 
} 
関連する問題