Skip to content

Commit

Permalink
Small improvements to build size (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankenny authored Oct 18, 2024
1 parent 41a62e3 commit 86f8068
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 27 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"browserslist": [
"supports es6-module"
],
"mangle": {
"regex": "_$"
},
"author": "The Chromium Authors",
"license": "Apache-2.0",
"keywords": [
Expand Down
10 changes: 5 additions & 5 deletions src/host-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class PostMessageCallbackMananger {
* @param {function(): undefined} callback
* @return {number} A handle that can used for cancellation.
*/
queueCallback(callback) {
queueCallback_(callback) {
// We support multiple pending postMessage callbacks by associating a handle
// with each message, which is used to look up the callback when the message
// is received.
Expand All @@ -70,7 +70,7 @@ class PostMessageCallbackMananger {
/**
* @param {number} handle The handle returned when the callback was queued.
*/
cancelCallback(handle) {
cancelCallback_(handle) {
delete this.messages_[handle];
}

Expand Down Expand Up @@ -161,7 +161,7 @@ class HostCallback {
* Returns true iff this task was scheduled with MessageChannel.
* @return {boolean}
*/
isMessageChannelCallback() {
isMessageChannelCallback_() {
return this.callbackType_ === CallbackType.POST_MESSAGE;
}

Expand All @@ -180,7 +180,7 @@ class HostCallback {
clearTimeout(this.handle_);
break;
case CallbackType.POST_MESSAGE:
getPostMessageCallbackManager().cancelCallback(this.handle_);
getPostMessageCallbackManager().cancelCallback_(this.handle_);
break;
default:
throw new TypeError('Unknown CallbackType');
Expand Down Expand Up @@ -228,7 +228,7 @@ class HostCallback {
// TODO: Consider using setTimeout in the background so tasks are
// throttled. One caveat here is that requestIdleCallback may not be
// throttled.
this.handle_ = getPostMessageCallbackManager().queueCallback(() => {
this.handle_ = getPostMessageCallbackManager().queueCallback_(() => {
this.runCallback_();
});
return;
Expand Down
37 changes: 18 additions & 19 deletions src/intrusive-task-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,6 @@ class IntrusiveTaskQueue {
}
}

/**
* Returns an array containing the elements of this task queue in order. This
* is meant to be used for debugging and might be removed.
*
* TODO(shaseley): consider removing this.
*
* @return {!Array<!Object>}
*/
toArray() {
let node = this.head_;
const a = [];
while (node !== null) {
a.push(node);
node = node.tq_next_;
}
return a;
}

/**
* Insert `task` into this queue directly after `parentTask`.
* @private
Expand Down Expand Up @@ -185,4 +167,21 @@ class IntrusiveTaskQueue {
}
}

export {IntrusiveTaskQueue};
/**
* Returns an array containing the elements of this task queue in order. This
* is meant to be used for debugging and might be removed.
*
* @param {IntrusiveTaskQueue} queue
* @return {!Array<!Object>}
*/
function toArray(queue) {
let node = queue.head_;
const a = [];
while (node !== null) {
a.push(node);
node = node.tq_next_;
}
return a;
}

export {IntrusiveTaskQueue, toArray};
6 changes: 3 additions & 3 deletions test/test.hostcallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('HostCallback', function() {
});


describe('#isMessageChannelCallback()', function() {
describe('#isMessageChannelCallback_()', function() {
let originalMessageChannel = null;

beforeEach(function() {
Expand All @@ -87,14 +87,14 @@ describe('HostCallback', function() {
it(`should use Message channel when avaliable for "${priority}"`,
function() {
const hostCallback = new HostCallback(() => {}, priority);
expect(hostCallback.isMessageChannelCallback()).to.equal(true);
expect(hostCallback.isMessageChannelCallback_()).to.equal(true);
});

it(`should not use Message channel when not avaliable for "${priority}"`,
function() {
window.MessageChannel = null;
const hostCallback = new HostCallback(() => {}, priority);
expect(hostCallback.isMessageChannelCallback()).to.equal(false);
expect(hostCallback.isMessageChannelCallback_()).to.equal(false);
});
});
});
Expand Down

0 comments on commit 86f8068

Please sign in to comment.