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

Never unsubscribe before receiving connected #58

Merged
merged 1 commit into from
Sep 22, 2020
Merged
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
22 changes: 18 additions & 4 deletions javascript/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@ import { version } from '../package.json'

export default class Component {
constructor (client, element) {
this._isShutdown = false

this.client = client
this.element = element

this._beforeConnect()

this._subscription = this.client.consumer.subscriptions.create(
const subscription = this.client.consumer.subscriptions.create(
{
channel: 'Motion::Channel',
version,
state: this.element.getAttribute(this.client.stateAttribute)
},
{
connected: () => this._connect(),
connected: () => {
if (this._isShutdown) {
subscription.unsubscribe()
return
}

this._subscription = subscription
this._connect()
},
rejected: () => this._connectFailed(),
disconnected: () => this._disconnect(),
received: newState => this._render(newState)
Expand Down Expand Up @@ -48,8 +58,12 @@ export default class Component {
}

shutdown () {
this._subscription.unsubscribe()
delete this._subscription
this._isShutdown = true

if (this._subscription) {
this._subscription.unsubscribe()
delete this._subscription
}

this._disconnect()
}
Expand Down