Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Integrating MsgPack support in TS client #699

Merged
merged 1 commit into from
Aug 11, 2017
Merged

Conversation

moozzyk
Copy link
Contributor

@moozzyk moozzyk commented Aug 9, 2017

No description provided.

export interface IHubProtocol {
name(): string;
type(): ProtocolType;
Copy link
Member

Choose a reason for hiding this comment

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

You can do real properties in typescript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not want them to be settable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(from JS that is...)

Copy link
Member

Choose a reason for hiding this comment

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

Cant you do get only properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can do readonly properties but they are only readonly in TypeScript but not in Javascript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

on the other hand you could replace the entire function in JS so meh - can change to a property (same for name())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

send(data: any): Promise<void>;
stop(): void;
onDataReceived: DataReceived;
onClosed: TransportClosed;
transferMode(): TransferMode;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am thinking about removing this and just returning Promise from connect. Same for connection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done()

@@ -112,10 +112,10 @@ describe("Connection", () => {
}
} as IHttpConnectionOptions;

var connection = new HttpConnection("http://tempuri.org", options);
let connection = new HttpConnection("http://tempuri.org", options);
Copy link

Choose a reason for hiding this comment

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

const connection instead? (here and elsewhere)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so - this is not an object literal so I don't think it makes any difference. Conceptually this object is not a const since it exposes onClosed and onDataReceived properties which are settable.

Copy link

Choose a reason for hiding this comment

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

I don't mind either way, but const only makes the variable constant (you can't assign something else to the name), not what the variable is referencing. (See readonly for that.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am leaving it as it is then. If we decide to change it to const we would probably have to change almost all variables which is out of scope for this PR. I was just annoyed by mixing let and var without any reason.

@@ -32,18 +32,18 @@ export class HttpConnection implements IConnection {
this.options = options;
}

async start(): Promise<void> {
async start(requestedTransferMode: TransferMode): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

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

This feels wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the alternative? Features? Adding Features felt to heavy for this. We can do this but it would come separately.

@@ -120,6 +120,14 @@ public class HubEndPoint<THub> : IInvocationBinder where THub : Hub
? (IDataEncoder)Base64Encoder
: PassThroughEncoder;

var transferMode = connection.Features.Get<ITransferModeFeature>() ??
Copy link
Contributor Author

@moozzyk moozzyk Aug 11, 2017

Choose a reason for hiding this comment

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

I now understand how this sneaked in - #711

@moozzyk
Copy link
Contributor Author

moozzyk commented Aug 11, 2017

🆙📅 - Added features to IConnection

readonly type: ProtocolType;

parseMessages(input: any): HubMessage[] {
// atob/btoa are browsers APIs but they can be polyfilled. If this becomes problematic we can use
Copy link
Member

Choose a reason for hiding this comment

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

File a bug for that. I don't want too many untracked browser deps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are we going to do anything about this though? I did try base64-js package and reverted the change since it added 2.2 KB to the library (minified) which is wasteful on browsers since the functionality is built-in. If you hit this on node you would need to polyfill. Unless the bug is supposed to be a doc bug which will be turned into a an article about dependencies a user needs to polyfill when running on node.

Copy link
Member

Choose a reason for hiding this comment

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

I can think of a few things we might do here:

  • Polyfill on nodejs - I hate this option
  • Dependency injection
  • Build a nodejs version with different sources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...we could also not support binary over SSE on node. I think XmlHttpRequest and WebSockets are more important - once we decide about these the atob/btoa replacement will just follow the suit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@moozzyk moozzyk force-pushed the pawelka/msgpack-js-integrate branch from 0b4008d to ed59d7f Compare August 11, 2017 18:26
@moozzyk moozzyk merged commit 4898c0d into dev Aug 11, 2017
@moozzyk moozzyk deleted the pawelka/msgpack-js-integrate branch August 23, 2017 23:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants