Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: lib/messaging.js

Issue 29339020: Issue 3868 - Use the new FilterNotifier API (Closed)
Left Patch Set: Created March 23, 2016, 8:15 p.m.
Right Patch Set: Updated depdendencies and use EventEmitter.listeners() Created March 24, 2016, 3:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/icon.js ('k') | lib/requestBlocker.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 { 30 {
31 this._eventEmitter = new EventEmitter(); 31 this._eventEmitter = new EventEmitter();
32 this._onMessage = this._onMessage.bind(this); 32 this._onMessage = this._onMessage.bind(this);
33 ext.onMessage.addListener(this._onMessage); 33 ext.onMessage.addListener(this._onMessage);
34 }; 34 };
35 35
36 Port.prototype = { 36 Port.prototype = {
37 _onMessage: function(message, sender, sendResponse) 37 _onMessage: function(message, sender, sendResponse)
38 { 38 {
39 let async = false; 39 let async = false;
40 let callbacks = this._eventEmitter._listeners[message.type]; 40 let callbacks = this._eventEmitter.listeners(message.type);
41 41
42 if (callbacks) 42 for (let callback of callbacks)
43 { 43 {
44 for (let callback of callbacks) 44 let response = callback(message, sender);
45
46 if (response && typeof response.then == "function")
45 { 47 {
46 let response = callback(message, sender); 48 response.then(
47 49 sendResponse,
48 if (response && typeof response.then == "function") 50 reason => {
49 { 51 console.error(reason);
50 response.then( 52 sendResponse(undefined);
51 sendResponse, 53 }
52 reason => { 54 );
53 console.error(reason); 55 async = true;
54 sendResponse(undefined); 56 }
55 } 57 else if (typeof response != "undefined")
56 ); 58 {
57 async = true; 59 sendResponse(response);
58 }
59 else if (typeof response != "undefined")
60 {
61 sendResponse(response);
62 }
63 } 60 }
64 } 61 }
65 62
66 return async; 63 return async;
67 }, 64 },
68 65
69 /** 66 /**
70 * Function to be called when a particular message is received. 67 * Function to be called when a particular message is received.
71 * 68 *
72 * @callback Port~messageCallback 69 * @callback Port~messageCallback
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 exports.getPort = function(window) 122 exports.getPort = function(window)
126 { 123 {
127 let port = new Port(); 124 let port = new Port();
128 window.addEventListener("unload", () => 125 window.addEventListener("unload", () =>
129 { 126 {
130 port.disconnect(); 127 port.disconnect();
131 }); 128 });
132 return port; 129 return port;
133 }; 130 };
134 131
LEFTRIGHT

Powered by Google App Engine
This is Rietveld