Commit 516420f9 authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #333 from...

Merge pull request #333 from hypothesis/fix-annotating-sites-with-broken-Function.bind-polyfills-take-3

Fix annotating sites with broken function.bind polyfills take 3
parents b0a27588 65b18b31
'use strict';
module.exports = {
rules: {
'no-restricted-properties': [2, {
// Disable `bind` usage in annotator/ code to prevent unexpected behavior
// due to broken bind polyfills. See
// https://github.com/hypothesis/client/issues/245
property: 'bind',
message: 'Use function expressions instead of bind() in annotator/ code'
}]
}
};
......@@ -6,10 +6,7 @@
// It also listens for events from Annotator when new annotations are created or
// annotations successfully anchor and relays these to the sidebar app.
function AnnotationSync(bridge, options) {
var event;
var func;
var handler;
var method;
var self = this;
this.bridge = bridge;
......@@ -27,20 +24,20 @@ function AnnotationSync(bridge, options) {
this._emit = options.emit;
// Listen locally for interesting events
for (event in this._eventListeners) {
if (Object.prototype.hasOwnProperty.call(this._eventListeners, event)) {
handler = this._eventListeners[event];
this._on(event, handler.bind(this));
}
}
Object.keys(this._eventListeners).forEach(function(eventName) {
var listener = self._eventListeners[eventName];
self._on(eventName, function(annotation) {
listener.apply(self, [annotation]);
});
});
// Register remotely invokable methods
for (method in this._channelListeners) {
if (Object.prototype.hasOwnProperty.call(this._channelListeners, method)) {
func = this._channelListeners[method];
this.bridge.on(method, func.bind(this));
}
}
Object.keys(this._channelListeners).forEach(function(eventName) {
self.bridge.on(eventName, function(data, callbackFunction) {
var listener = self._channelListeners[eventName];
listener.apply(self, [data, callbackFunction]);
});
});
}
// Cache of annotations which have crossed the bridge for fast, encapsulated
......
......@@ -42,7 +42,7 @@ module.exports = class Sidebar extends Host
this._setupSidebarEvents()
_setupDocumentEvents: ->
sidebarTrigger(document.body, @show.bind(this))
sidebarTrigger(document.body, => this.show())
@element.on 'click', (event) =>
if !@selectedTargets?.length
......@@ -62,8 +62,8 @@ module.exports = class Sidebar extends Host
_setupSidebarEvents: ->
annotationCounts(document.body, @crossframe)
@crossframe.on('show', this.show.bind(this))
@crossframe.on('hide', this.hide.bind(this))
@crossframe.on('show', => this.show())
@crossframe.on('hide', => this.hide())
@crossframe.on(events.DO_LOGIN, =>
if @onLoginRequest
@onLoginRequest()
......
......@@ -29,8 +29,8 @@ describe('AnnotationSync', function() {
};
options = {
on: emitter.on.bind(emitter),
emit: emitter.emit.bind(emitter),
on: emitter.on.bind(emitter), // eslint-disable-line no-restricted-properties
emit: emitter.emit.bind(emitter), // eslint-disable-line no-restricted-properties
};
publish = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment