-
Notifications
You must be signed in to change notification settings - Fork 8
Decorators #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Decorators #45
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||
| import Monitor from './Monitor'; | ||||||
| import {MonitoredOptions} from './types'; | ||||||
|
|
||||||
| let instance: Monitor | undefined; | ||||||
|
|
||||||
|
|
@@ -15,10 +16,19 @@ export function getGlobalInstance(): Monitor { | |||||
| } | ||||||
|
|
||||||
| export const monitored: Monitor['monitored'] = (...args) => getGlobalInstance().monitored(...args); | ||||||
|
|
||||||
| /** | ||||||
| * @deprecated since version 2.0 | ||||||
| */ | ||||||
| export const getStatsdClient: Monitor['getStatsdClient'] = (...args) => getGlobalInstance().getStatsdClient(...args); | ||||||
| export const increment: Monitor['increment'] = (...args) => getGlobalInstance().increment(...args); | ||||||
| export const gauge: Monitor['gauge'] = (...args) => getGlobalInstance().gauge(...args); | ||||||
| export const timing: Monitor['timing'] = (...args) => getGlobalInstance().timing(...args); | ||||||
|
|
||||||
| export const monitorMethod = <T>(prefix?: string, options: MonitoredOptions<T> = {}) => { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd replace I want to avoid Or, just make |
||||||
| return function (_target: Object, propertyKey: string, descriptor: PropertyDescriptor) { | ||||||
| const originalMethod = descriptor.value; | ||||||
| const metricName = `${prefix}${prefix ? '.' : ''}${propertyKey}`; | ||||||
| descriptor.value = monitored(metricName, originalMethod, options); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
monitored calls the method, you need |
||||||
| }; | ||||||
| }; | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,9 @@ | |
| "lib": ["dom", "es2017"], | ||
| "skipLibCheck": true, | ||
| "noImplicitAny": false, | ||
| "useUnknownInCatchVariables": false | ||
| "useUnknownInCatchVariables": false, | ||
| "experimentalDecorators": true | ||
| }, | ||
| "include": ["src/**/*", "types/*.d.ts"], | ||
| "include": ["src/**/*", "types/*.d.ts", "example/**/*"], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ensure that it does not cause |
||
| "exclude": ["__tests__", "dist"] | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.