mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-08-26 11:12:19 +08:00
Changed tabs to spaces
This commit is contained in:
@@ -2,76 +2,76 @@
|
||||
/// <reference path='../angularjs/angular.d.ts' />
|
||||
|
||||
angular
|
||||
.module('app', ['SignalR'])
|
||||
.factory('Employees', ngSignalrTest.EmployeesFactory);
|
||||
.module('app', ['SignalR'])
|
||||
.factory('Employees', ngSignalrTest.EmployeesFactory);
|
||||
|
||||
module ngSignalrTest {
|
||||
export class EmployeesFactory {
|
||||
static $inject = ['$rootScope', 'Hub', '$timeout'];
|
||||
private hub: ngSignalr.Hub;
|
||||
public all: Array<Employee>;
|
||||
|
||||
constructor($rootScope: ng.IRootScopeService, Hub: ngSignalr.HubFactory, $timeout: ng.ITimeoutService) {
|
||||
// declaring the hub connection
|
||||
this.hub = new Hub('employee', {
|
||||
// client-side methods
|
||||
listeners: {
|
||||
'lockEmployee': (id: number) => {
|
||||
var employee = this.find(id);
|
||||
employee.Locked = true;
|
||||
$rootScope.$apply();
|
||||
},
|
||||
'unlockEmployee': (id: number) => {
|
||||
var employee = this.find(id);
|
||||
employee.Locked = false;
|
||||
$rootScope.$apply();
|
||||
}
|
||||
},
|
||||
|
||||
// server-side methods
|
||||
methods: ['lock', 'unlock'],
|
||||
|
||||
// query params sent on initial connection
|
||||
queryParams:{
|
||||
'token': 'exampletoken'
|
||||
},
|
||||
|
||||
// handle connection error
|
||||
errorHandler: (message: string) => {
|
||||
console.error(message);
|
||||
},
|
||||
|
||||
stateChanged: (state: SignalRStateChange) => {
|
||||
// your code here
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private find(id: number) {
|
||||
for (var i = 0; i < this.all.length; i++) {
|
||||
if (this.all[i].Id === id) return this.all[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public edit = (employee: Employee) => {
|
||||
employee.Edit = true;
|
||||
this.hub.invoke('lock', employee.Id);
|
||||
};
|
||||
|
||||
public done = (employee: Employee) => {
|
||||
employee.Edit = false;
|
||||
this.hub.invoke('unlock', employee.Id);
|
||||
}
|
||||
}
|
||||
|
||||
interface Employee {
|
||||
Id: number;
|
||||
Name: string;
|
||||
Email: string;
|
||||
Salary: number;
|
||||
Edit: boolean;
|
||||
Locked: boolean;
|
||||
}
|
||||
export class EmployeesFactory {
|
||||
static $inject = ['$rootScope', 'Hub', '$timeout'];
|
||||
private hub: ngSignalr.Hub;
|
||||
public all: Array<Employee>;
|
||||
|
||||
constructor($rootScope: ng.IRootScopeService, Hub: ngSignalr.HubFactory, $timeout: ng.ITimeoutService) {
|
||||
// declaring the hub connection
|
||||
this.hub = new Hub('employee', {
|
||||
// client-side methods
|
||||
listeners: {
|
||||
'lockEmployee': (id: number) => {
|
||||
var employee = this.find(id);
|
||||
employee.Locked = true;
|
||||
$rootScope.$apply();
|
||||
},
|
||||
'unlockEmployee': (id: number) => {
|
||||
var employee = this.find(id);
|
||||
employee.Locked = false;
|
||||
$rootScope.$apply();
|
||||
}
|
||||
},
|
||||
|
||||
// server-side methods
|
||||
methods: ['lock', 'unlock'],
|
||||
|
||||
// query params sent on initial connection
|
||||
queryParams:{
|
||||
'token': 'exampletoken'
|
||||
},
|
||||
|
||||
// handle connection error
|
||||
errorHandler: (message: string) => {
|
||||
console.error(message);
|
||||
},
|
||||
|
||||
stateChanged: (state: SignalRStateChange) => {
|
||||
// your code here
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private find(id: number) {
|
||||
for (var i = 0; i < this.all.length; i++) {
|
||||
if (this.all[i].Id === id) return this.all[i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public edit = (employee: Employee) => {
|
||||
employee.Edit = true;
|
||||
this.hub.invoke('lock', employee.Id);
|
||||
};
|
||||
|
||||
public done = (employee: Employee) => {
|
||||
employee.Edit = false;
|
||||
this.hub.invoke('unlock', employee.Id);
|
||||
}
|
||||
}
|
||||
|
||||
interface Employee {
|
||||
Id: number;
|
||||
Name: string;
|
||||
Email: string;
|
||||
Salary: number;
|
||||
Edit: boolean;
|
||||
Locked: boolean;
|
||||
}
|
||||
}
|
||||
+64
-64
@@ -6,68 +6,68 @@
|
||||
/// <reference path='../signalr/signalr.d.ts' />
|
||||
|
||||
declare module ngSignalr {
|
||||
interface HubFactory {
|
||||
/**
|
||||
* Creates a new Hub connection
|
||||
*/
|
||||
new(hubName: string, options: HubOptions) : Hub
|
||||
}
|
||||
|
||||
class Hub {
|
||||
hubName: string;
|
||||
connection: SignalR;
|
||||
proxy: HubProxy;
|
||||
|
||||
on(event: string, fn: ((...args: any[]) => void)): void;
|
||||
invoke(method: string, ...args: any[]): JQueryDeferred<any>;
|
||||
disconnect(): void;
|
||||
connect(): JQueryPromise<any>;
|
||||
}
|
||||
|
||||
interface HubOptions {
|
||||
/**
|
||||
* Collection of client side callbacks
|
||||
*/
|
||||
listeners?: { [index: string] : (...args: any[]) => void };
|
||||
|
||||
/**
|
||||
* String array of server side methods which the client can call
|
||||
*/
|
||||
methods?: Array<string>;
|
||||
|
||||
/**
|
||||
* Sets the root path for the SignalR web service
|
||||
*/
|
||||
rootPath?: string;
|
||||
|
||||
/**
|
||||
* Object representing additional query params to be sent on connection
|
||||
*/
|
||||
queryParams?: { [index: string] : string };
|
||||
|
||||
/**
|
||||
* Function to handle hub connection errors
|
||||
*/
|
||||
errorHandler?: (error: string) => void;
|
||||
|
||||
/**
|
||||
* Enable/disable logging
|
||||
*/
|
||||
logging?: boolean;
|
||||
|
||||
/**
|
||||
* Use a shared global connection or create a new one just for this hub, defaults to true
|
||||
*/
|
||||
useSharedConnection?: boolean;
|
||||
|
||||
/**
|
||||
* Sets transport method (e.g 'longPolling' or ['webSockets', 'longPolling'] )
|
||||
*/
|
||||
transport?: any;
|
||||
|
||||
/**
|
||||
* Function to handle hub connection state changed event
|
||||
*/
|
||||
stateChanged?: (state: SignalRStateChange) => void;
|
||||
}
|
||||
interface HubFactory {
|
||||
/**
|
||||
* Creates a new Hub connection
|
||||
*/
|
||||
new(hubName: string, options: HubOptions) : Hub
|
||||
}
|
||||
|
||||
class Hub {
|
||||
hubName: string;
|
||||
connection: SignalR;
|
||||
proxy: HubProxy;
|
||||
|
||||
on(event: string, fn: ((...args: any[]) => void)): void;
|
||||
invoke(method: string, ...args: any[]): JQueryDeferred<any>;
|
||||
disconnect(): void;
|
||||
connect(): JQueryPromise<any>;
|
||||
}
|
||||
|
||||
interface HubOptions {
|
||||
/**
|
||||
* Collection of client side callbacks
|
||||
*/
|
||||
listeners?: { [index: string] : (...args: any[]) => void };
|
||||
|
||||
/**
|
||||
* String array of server side methods which the client can call
|
||||
*/
|
||||
methods?: Array<string>;
|
||||
|
||||
/**
|
||||
* Sets the root path for the SignalR web service
|
||||
*/
|
||||
rootPath?: string;
|
||||
|
||||
/**
|
||||
* Object representing additional query params to be sent on connection
|
||||
*/
|
||||
queryParams?: { [index: string] : string };
|
||||
|
||||
/**
|
||||
* Function to handle hub connection errors
|
||||
*/
|
||||
errorHandler?: (error: string) => void;
|
||||
|
||||
/**
|
||||
* Enable/disable logging
|
||||
*/
|
||||
logging?: boolean;
|
||||
|
||||
/**
|
||||
* Use a shared global connection or create a new one just for this hub, defaults to true
|
||||
*/
|
||||
useSharedConnection?: boolean;
|
||||
|
||||
/**
|
||||
* Sets transport method (e.g 'longPolling' or ['webSockets', 'longPolling'] )
|
||||
*/
|
||||
transport?: any;
|
||||
|
||||
/**
|
||||
* Function to handle hub connection state changed event
|
||||
*/
|
||||
stateChanged?: (state: SignalRStateChange) => void;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user