mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
adding microgears definitions (#8930)
This commit is contained in:
committed by
Masahiro Wakame
parent
d890dbd5f3
commit
b572283659
58
microgears/microgears-tests.ts
Normal file
58
microgears/microgears-tests.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
/// <reference path="microgears.d.ts" />
|
||||
|
||||
|
||||
function verify_module_file() {
|
||||
var tracePlugin = new TracePlugin();
|
||||
microgears.addPlugin(tracePlugin);
|
||||
var service = new UserService();
|
||||
var userService = microgears.addService(service);
|
||||
|
||||
|
||||
}
|
||||
|
||||
class TracePlugin implements microgears.Plugin {
|
||||
name: 'TracePlugin';
|
||||
public beforeChain(args:Array<any>, _meta: microgears.MetaInformation) {
|
||||
var serviceName = _meta.serviceName,
|
||||
method = _meta.methodName;
|
||||
console.log('before call-> ' + serviceName + '.' + method);
|
||||
|
||||
_meta.extra = {
|
||||
count: 1
|
||||
};
|
||||
|
||||
return args
|
||||
}
|
||||
public afterChain(result:any, _meta: microgears.MetaInformation) {
|
||||
var serviceName = _meta.serviceName,
|
||||
method = _meta.methodName;
|
||||
|
||||
console.log('after of-> ' + serviceName + '.' + method);
|
||||
if (_meta.extra.count) {
|
||||
console.log('this number comes to the beforeChain: ' + _meta.extra.count);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
class User {
|
||||
name: string;
|
||||
email: string;
|
||||
|
||||
constructor(name: string, email: string) {
|
||||
this.email = email;
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
class UserService implements microgears.Service {
|
||||
name: string = "userService";
|
||||
namespace: string = "services.user";
|
||||
|
||||
public findUserById(id: number) {
|
||||
return new User('test', 'test@example.com');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
33
microgears/microgears.d.ts
vendored
Normal file
33
microgears/microgears.d.ts
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
// Type definitions for microgears v4.0.0
|
||||
// Project: http://github.com/marcusdb/microgears
|
||||
// Definitions by: Marcus David Bronstein <https://github.com/marcusdb>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace microgears {
|
||||
export interface Service {
|
||||
name: string;
|
||||
async?: boolean;
|
||||
pathname?: string;
|
||||
namespace: string;
|
||||
}
|
||||
|
||||
interface MetaInformation {
|
||||
serviceName: string;
|
||||
methodName: string;
|
||||
serviceNameSpace: string;
|
||||
extra: any;
|
||||
}
|
||||
|
||||
interface Plugin {
|
||||
name: string;
|
||||
beforeChain(arguments: Array<any>, metaInfo: MetaInformation): Array<any>;
|
||||
afterChain<T>(result: T, metaInfo: MetaInformation): T;
|
||||
}
|
||||
|
||||
function addService(service: Service): Service;
|
||||
function addPlugin(plugin: Plugin): void;
|
||||
}
|
||||
|
||||
declare module "microgears" {
|
||||
export = microgears;
|
||||
}
|
||||
Reference in New Issue
Block a user