Skip to content

Commit

Permalink
Restructure Typescript project
Browse files Browse the repository at this point in the history
Configure TS compile options
Update dependencies
Update Blazor to 0.5.1
Move JS initialization from global to extension specific namespace
Fix name in PR CI build file
  • Loading branch information
attilah committed Jul 29, 2018
1 parent 4194f50 commit 9e2cfa5
Show file tree
Hide file tree
Showing 18 changed files with 204 additions and 96 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
dist/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Blazor Extensions
Copyright (c) 2018 Blazor Extensions Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "2.1.302"
}
}
2 changes: 0 additions & 2 deletions src/Blazor.Extensions.SignalR.JS/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<OutputType>Library</OutputType>
<IsPackable>false</IsPackable>
<BlazorLinkOnBuild>false</BlazorLinkOnBuild>
<LangVersion>latest</LangVersion>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
<DefaultItemExcludes>${DefaultItemExcludes};dist\**;node_modules\**</DefaultItemExcludes>
Expand Down
129 changes: 85 additions & 44 deletions src/Blazor.Extensions.SignalR.JS/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/Blazor.Extensions.SignalR.JS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
},
"devDependencies": {
"@types/emscripten": "0.0.31",
"webpack": "^4.16.0",
"webpack-cli": "^3.0.8",
"ts-loader": "^4.4.2",
"typescript": "^2.9.2",
"ts-loader": "^4.4.2"
"webpack": "^4.16.3",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"@aspnet/signalr": "^1.0.2",
Expand Down
15 changes: 12 additions & 3 deletions src/Blazor.Extensions.SignalR.JS/src/HubConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ type DotNetReferenceType = {
invokeMethodAsync<T>(methodIdentifier: string, ...args: any[]): Promise<T>
}

const DotNet: DotNetType = window["DotNet"];

export class HubConnectionManager {
private _hubConnections: Map<string, signalR.HubConnection> = new Map<string, signalR.HubConnection>();
private _handles: Map<string, (payload: any) => Promise<void>> = new Map<string, (payload: any) => Promise<void>>();

public CreateConnection = (connectionId: string, httpConnectionOptions: DotNetReferenceType) => {
if (!connectionId) throw new Error('Invalid connectionId.');
if (!httpConnectionOptions) throw new Error('Invalid transport options.');
let url = httpConnectionOptions.invokeMethod<string>('get_Url');

const url = httpConnectionOptions.invokeMethod<string>('get_Url');

if (!url) throw new Error('Invalid hub url.');

let options: any = {
Expand Down Expand Up @@ -75,17 +75,21 @@ export class HubConnectionManager {

public InvokeAsync = (connectionId: string, methodName: string, args: any[]): Promise<void> => {
const connection = this.GetConnection(connectionId);

return connection.invoke(methodName, ...args);
}

public InvokeWithResultAsync = (connectionId: string, methodName: string, args: any[]): Promise<any> => {
const connection = this.GetConnection(connectionId);

return connection.invoke(methodName, ...args);
}

private GetConnection = (connectionId: string) => {
if (!connectionId) throw new Error('Invalid connectionId.');

const connection = this._hubConnections.get(connectionId);

if (!connection) throw new Error('Invalid connection.');

return connection;
Expand All @@ -94,21 +98,26 @@ export class HubConnectionManager {
public On = (connectionId: string, callback: DotNetReferenceType) => {
const connection = this.GetConnection(connectionId);
const handle = (payload) => callback.invokeMethodAsync<void>('On', JSON.stringify(payload));

this._handles.set(callback.invokeMethod<string>('get_Id'), handle);

connection.on(callback.invokeMethod<string>('get_MethodName'), handle);
}

public Off = (connectionId: string, methodName: string, handleId: string) => {
const connection = this.GetConnection(connectionId);
const handle = this._handles.get(handleId);

if (handle) {
connection.off(methodName, handle);

this._handles.delete(handleId);
}
}

public OnClose = (connectionId: string, onErrorCallback: DotNetReferenceType) => {
const connection = this.GetConnection(connectionId);

connection.onclose(async err => {
onErrorCallback.invokeMethodAsync<void>('OnClose', JSON.stringify(err));
});
Expand Down
22 changes: 0 additions & 22 deletions src/Blazor.Extensions.SignalR.JS/src/Initialize.ts

This file was deleted.

Loading

0 comments on commit 9e2cfa5

Please sign in to comment.