1 | declare module '@ember/instrumentation' {
|
2 | export interface Listener<T> {
|
3 | before: (name: string, timestamp: number, payload: object) => T;
|
4 | after: (name: string, timestamp: number, payload: object, beforeValue: T) => void;
|
5 | }
|
6 | export interface Subscriber<T> {
|
7 | pattern: string;
|
8 | regex: RegExp;
|
9 | object: Listener<T>;
|
10 | }
|
11 | export interface PayloadWithException {
|
12 | exception?: any;
|
13 | }
|
14 | export interface StructuredProfilePayload {
|
15 | object: string | object;
|
16 | }
|
17 | /**
|
18 | @module @ember/instrumentation
|
19 | @private
|
20 | */
|
21 | /**
|
22 | The purpose of the Ember Instrumentation module is
|
23 | to provide efficient, general-purpose instrumentation
|
24 | for Ember.
|
25 |
|
26 | Subscribe to a listener by using `subscribe`:
|
27 |
|
28 | ```javascript
|
29 | import { subscribe } from '@ember/instrumentation';
|
30 |
|
31 | subscribe("render", {
|
32 | before(name, timestamp, payload) {
|
33 |
|
34 | },
|
35 |
|
36 | after(name, timestamp, payload) {
|
37 |
|
38 | }
|
39 | });
|
40 | ```
|
41 |
|
42 | If you return a value from the `before` callback, that same
|
43 | value will be passed as a fourth parameter to the `after`
|
44 | callback.
|
45 |
|
46 | Instrument a block of code by using `instrument`:
|
47 |
|
48 | ```javascript
|
49 | import { instrument } from '@ember/instrumentation';
|
50 |
|
51 | instrument("render.handlebars", payload, function() {
|
52 | // rendering logic
|
53 | }, binding);
|
54 | ```
|
55 |
|
56 | Event names passed to `instrument` are namespaced
|
57 | by periods, from more general to more specific. Subscribers
|
58 | can listen for events by whatever level of granularity they
|
59 | are interested in.
|
60 |
|
61 | In the above example, the event is `render.handlebars`,
|
62 | and the subscriber listened for all events beginning with
|
63 | `render`. It would receive callbacks for events named
|
64 | `render`, `render.handlebars`, `render.container`, or
|
65 | even `render.handlebars.layout`.
|
66 |
|
67 | @class Instrumentation
|
68 | @static
|
69 | @private
|
70 | */
|
71 | export let subscribers: Subscriber<any>[];
|
72 | type InstrumentCallback<Binding, Result> = (this: Binding) => Result;
|
73 | /**
|
74 | Notifies event's subscribers, calls `before` and `after` hooks.
|
75 |
|
76 | @method instrument
|
77 | @for @ember/instrumentation
|
78 | @static
|
79 | @param {String} [name] Namespaced event name.
|
80 | @param {Object} payload
|
81 | @param {Function} callback Function that you're instrumenting.
|
82 | @param {Object} binding Context that instrument function is called with.
|
83 | @private
|
84 | */
|
85 | export function instrument<Result>(
|
86 | name: string,
|
87 | callback: InstrumentCallback<undefined, Result>
|
88 | ): Result;
|
89 | export function instrument<Binding, Result>(
|
90 | name: string,
|
91 | callback: InstrumentCallback<Binding, Result>,
|
92 | binding: Binding
|
93 | ): Result;
|
94 | export function instrument<Result>(
|
95 | name: string,
|
96 | payload: object,
|
97 | callback: InstrumentCallback<undefined, Result>
|
98 | ): Result;
|
99 | export function instrument<Binding, Result>(
|
100 | name: string,
|
101 | payload: object,
|
102 | callback: InstrumentCallback<Binding, Result>,
|
103 | binding: Binding
|
104 | ): Result;
|
105 | export function flaggedInstrument<Result>(
|
106 | _name: string,
|
107 | _payload: object,
|
108 | callback: () => Result
|
109 | ): Result;
|
110 | export function _instrumentStart(name: string, payloadFunc: () => object): () => void;
|
111 | export function _instrumentStart<Arg>(
|
112 | name: string,
|
113 | payloadFunc: (arg: Arg) => object,
|
114 | payloadArg: Arg
|
115 | ): () => void;
|
116 | /**
|
117 | Subscribes to a particular event or instrumented block of code.
|
118 |
|
119 | @method subscribe
|
120 | @for @ember/instrumentation
|
121 | @static
|
122 |
|
123 | @param {String} [pattern] Namespaced event name.
|
124 | @param {Object} [object] Before and After hooks.
|
125 |
|
126 | @return {Subscriber}
|
127 | @private
|
128 | */
|
129 | export function subscribe<T>(pattern: string, object: Listener<T>): Subscriber<T>;
|
130 | /**
|
131 | Unsubscribes from a particular event or instrumented block of code.
|
132 |
|
133 | @method unsubscribe
|
134 | @for @ember/instrumentation
|
135 | @static
|
136 |
|
137 | @param {Object} [subscriber]
|
138 | @private
|
139 | */
|
140 | export function unsubscribe(subscriber: Subscriber<any>): void;
|
141 | /**
|
142 | Resets `Instrumentation` by flushing list of subscribers.
|
143 |
|
144 | @method reset
|
145 | @for @ember/instrumentation
|
146 | @static
|
147 | @private
|
148 | */
|
149 | export function reset(): void;
|
150 | export {};
|
151 | }
|