Skip to content

Commit

Permalink
seperate extract methoddescription method
Browse files Browse the repository at this point in the history
  • Loading branch information
joesonw committed Aug 7, 2017
1 parent dd18ce7 commit 0cbfa4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@t2ee/restful",
"version": "1.0.1",
"version": "1.0.2",
"description": "restful",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
24 changes: 14 additions & 10 deletions src/RestfulService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,19 @@ export default class RestfulService {
}

public create<T>(service: new (...args) => T): T {
const description = this.extract(service);
return new Proxy({} as any, new RestfulClient(
description,
this._baseUrl,
this._headers,
this._params,
this._query,
this._json,
this._fields,
));
}

public extract<T>(service: new (...args) => T): {[key: string]: MethodDescription} {
const description: {[key: string]: MethodDescription} = {};
const methods = Metadata.get('t2ee:restful:method', service.prototype);
for (const key in methods) {
Expand All @@ -93,15 +106,6 @@ export default class RestfulService {
type: Metadata.get(`t2ee:restful:method:${key}:type`, service.prototype) || 'json',
};
}
return new Proxy({} as any, new RestfulClient(
description,
this._baseUrl,
this._headers,
this._params,
this._query,
this._json,
this._fields,
));
return description;
}

}

0 comments on commit 0cbfa4d

Please sign in to comment.