teletype-client-modified
Version:
I have modified the library developed by Atom to make it compatible with non-browser facility. I am using it only for experimentation purposes. I will remove this package post my experiment and raise a PR at Atom to finally merge this package so that this
51 lines (45 loc) • 1.48 kB
JavaScript
const Messages = require('./teletype-client_pb')
const {CompositeDisposable} = require('event-kit')
const NOOP = () => {}
module.exports =
class EditorProxyMetadata {
static deserialize (message, props) {
return new EditorProxyMetadata(Object.assign({
id: message.getId(),
bufferProxyId: message.getBufferProxyId(),
bufferProxyURI: message.getBufferProxyUri()
}, props))
}
constructor ({id, bufferProxyId, bufferProxyURI, siteId, router, didDispose}) {
this.id = id
this.bufferProxyId = bufferProxyId
this.bufferProxyURI = bufferProxyURI
this.subscriptions = new CompositeDisposable()
this.didDispose = didDispose || NOOP
if (didDispose) {
this.subscriptions.add(
router.onNotification(`/buffers/${id}`, this.receiveBufferUpdate.bind(this))
)
this.subscriptions.add(
router.onNotification(`/editors/${id}/disposal`, this.dispose.bind(this))
)
}
}
dispose () {
this.subscriptions.dispose()
this.didDispose()
}
serialize () {
const message = new Messages.EditorProxyMetadata()
message.setId(this.id)
message.setBufferProxyId(this.bufferProxyId)
message.setBufferProxyUri(this.bufferProxyURI)
return message
}
receiveBufferUpdate ({body}) {
const updateMessage = Messages.BufferProxyUpdate.deserializeBinary(body)
if (updateMessage.hasUriUpdate()) {
this.bufferProxyURI = updateMessage.getUriUpdate().getUri()
}
}
}