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

Uprade to comlink v4 #10149

Merged
merged 5 commits into from
Apr 23, 2020
Merged

Uprade to comlink v4 #10149

merged 5 commits into from
Apr 23, 2020

Conversation

felixfbecker
Copy link
Contributor

@felixfbecker felixfbecker commented Apr 23, 2020

Closes #3989.

There were a bunch or renames, and StringMessageChannelAdapter is no longer bundled with comlink. There is a new experimental string channel support, that is less leaky.

Corresponding upstream comlink PR to fix types: GoogleChromeLabs/comlink#451

Tested manually in the webapp and browser extension.

@felixfbecker felixfbecker changed the title Uprade to comlink v4 (fork) Uprade to comlink v4 Apr 23, 2020
@felixfbecker
Copy link
Contributor Author

felixfbecker commented Apr 23, 2020

The test failure is a bug in Babel 😮

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ExtLanguageFeatures = void 0;

var _comlink = require("@sourcegraph/comlink");

var _util = require("../../util");

var _common = require("./common");

var _types = require("./types");

/* eslint-disable no-sync */

/** @internal */
class ExtLanguageFeatures {
  constructor(proxy, documents) {
    this.proxy = _comlink.proxy; // should be proxy, not _comlink.proxy!
    this.documents = documents;
  }

@codecov
Copy link

codecov bot commented Apr 23, 2020

Codecov Report

Merging #10149 into master will increase coverage by 0.00%.
The diff coverage is 67.46%.

@@           Coverage Diff           @@
##           master   #10149   +/-   ##
=======================================
  Coverage   42.77%   42.77%           
=======================================
  Files        1348     1348           
  Lines       74137    74136    -1     
  Branches     6651     6659    +8     
=======================================
+ Hits        31711    31712    +1     
+ Misses      39570    39568    -2     
  Partials     2856     2856           
Flag Coverage Δ
#unit 42.77% <67.46%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
browser/src/extension/scripts/background.ts 0.00% <0.00%> (ø)
browser/src/platform/extensionHost.ts 28.57% <0.00%> (+7.73%) ⬆️
shared/src/api/extension/api/codeEditor.ts 83.33% <ø> (ø)
shared/src/api/extension/main.worker.ts 0.00% <0.00%> (ø)
shared/src/platform/context.ts 0.00% <0.00%> (ø)
shared/src/api/client/api/windows.ts 84.61% <33.33%> (ø)
shared/src/api/util.ts 76.92% <66.66%> (-1.34%) ⬇️
shared/src/api/client/api/languageFeatures.ts 82.35% <81.81%> (ø)
shared/src/api/extension/api/languageFeatures.ts 80.00% <83.33%> (ø)
shared/src/api/client/api/codeEditor.ts 83.33% <100.00%> (ø)
... and 22 more

@felixfbecker felixfbecker marked this pull request as ready for review April 23, 2020 11:54
@felixfbecker felixfbecker requested a review from a team April 23, 2020 11:54
@felixfbecker felixfbecker added debt Technical debt. team/web labels Apr 23, 2020
@felixfbecker felixfbecker added this to Needs review in Web Team :: Current iteration via automation Apr 23, 2020
@felixfbecker felixfbecker added this to the 3.16 milestone Apr 23, 2020
@lguychard lguychard mentioned this pull request Apr 23, 2020
41 tasks
Copy link
Contributor

@lguychard lguychard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I much prefer the local/remote naming 👍


export const isEndpointPair = (value: unknown): value is EndpointPair =>
isObject(value) &&
hasProperty('proxy')(value) &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're going to use hasProperty a lot more, what would you think about having curriedHasProperty() (maybe there's a better name) and hasProperty()?

filter(curriedHasProperty('postMessage'))

// or
const isFoo = (bar: unknown) => hasProperty('foo', bar)

The hasProperty()() syntax is a bit alien/odd and I'd like to avoid odd patterns from proliferating in our codebase as much as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this too, and I had the same initial reaction. But I thought it would be weird/annoying to have the "curried" prefix and dual versions for every type guard too. One thought I had was that this may be one of these things that feel weird at first but you get used to it quickly.

Another thing I thought about was having a function to compose type guards, like all(...typeGuards)(value). That would avoid having to repeat the call with value for every type guard. I haven't found out how to type that yet though.

Ideally TypeScript would also just implement microsoft/TypeScript#21732 (which will happen eventually, given it has the label Committed), and then we can just use the in operator in non-functional contexts, while hasProperty() continues to serve the curried use case (and in that scenario, it would be nice if it doesn't need the "curried" prefix).

I propose we just leave it as-is for a bit and see where it goes (maybe improve with an all() helper, and/or maybe TS will ship in support sometime this year).

Web Team :: Current iteration automation moved this from Needs review to Reviewer approved Apr 23, 2020
@felixfbecker felixfbecker merged commit e26e974 into master Apr 23, 2020
Web Team :: Current iteration automation moved this from Reviewer approved to Done Apr 23, 2020
@felixfbecker felixfbecker deleted the comlink-v4 branch April 23, 2020 15:06
notjrbauer pushed a commit to notjrbauer/sourcegraph that referenced this pull request Apr 25, 2020
* Uprade to comlink v4 (fork)

* Workaround Babel bug

TypeScript property initializers and named imports compiled to CommonJS
name-conflict and result in the wrong value being assigned.

* Use new string channel

From https://github.com/GoogleChromeLabs/comlink/blob/string-channel/src/string-channel.experimental.ts

* Fix browser extension decoration tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
debt Technical debt.
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Update to comlink v4
2 participants