@leafer/debug 1.0.0-rc.6 → 1.0.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leafer/debug",
3
- "version": "1.0.0-rc.6",
3
+ "version": "1.0.0-rc.8",
4
4
  "description": "@leafer/debug",
5
5
  "author": "Chao (Leafer) Wan",
6
6
  "license": "MIT",
@@ -22,9 +22,9 @@
22
22
  "leaferjs"
23
23
  ],
24
24
  "dependencies": {
25
- "@leafer/math": "1.0.0-rc.6"
25
+ "@leafer/math": "1.0.0-rc.8"
26
26
  },
27
27
  "devDependencies": {
28
- "@leafer/interface": "1.0.0-rc.6"
28
+ "@leafer/interface": "1.0.0-rc.8"
29
29
  }
30
30
  }
package/src/Debug.ts CHANGED
@@ -45,10 +45,14 @@ export class Debug {
45
45
  }
46
46
  }
47
47
 
48
- warn(...messages: unknown[]): void {
48
+ tip(...messages: unknown[]): void {
49
49
  if (D.enable) console.warn(this.name, ...messages)
50
50
  }
51
51
 
52
+ warn(...messages: unknown[]): void {
53
+ console.warn(this.name, ...messages)
54
+ }
55
+
52
56
  repeat(name: string, ...messages: unknown[]) {
53
57
  if (!this.repeatMap[name]) {
54
58
  this.warn('repeat:' + name, ...messages)
package/src/Run.ts CHANGED
@@ -12,37 +12,31 @@ interface names {
12
12
 
13
13
  const debug = Debug.get('RunTime')
14
14
 
15
- export class Run {
15
+ export const Run = {
16
16
 
17
- static currentId: number
18
- static currentTime: number
19
- static currentName: string
17
+ currentId: 0,
18
+ currentName: '',
20
19
 
21
- static idMap: ids = {}
22
- static nameMap: names = {}
23
- static nameToIdMap: ids = {}
20
+ idMap: {} as ids,
21
+ nameMap: {} as names,
22
+ nameToIdMap: {} as ids,
24
23
 
25
- static start(name: string, microsecond?: boolean): number {
24
+ start(name: string, microsecond?: boolean): number {
26
25
  const id = IncrementId.create(IncrementId.RUNTIME)
27
26
  R.currentId = R.idMap[id] = microsecond ? performance.now() : Date.now()
28
27
  R.currentName = R.nameMap[id] = name
29
28
  R.nameToIdMap[name] = id
30
29
  return id
31
- }
30
+ },
32
31
 
33
- static end(id: number, microsecond?: boolean): void {
34
- const time = R.idMap[id]
35
- const name = R.nameMap[id]
32
+ end(id: number, microsecond?: boolean): void {
33
+ const time = R.idMap[id], name = R.nameMap[id]
34
+ const duration = microsecond ? (performance.now() - time) / 1000 : Date.now() - time
36
35
  R.idMap[id] = R.nameMap[id] = R.nameToIdMap[name] = undefined
36
+ debug.log(name, duration, 'ms')
37
+ },
37
38
 
38
- if (microsecond) {
39
- debug.log(name, performance.now() - time, 'µs')
40
- } else {
41
- debug.log(name, Date.now() - time, 'ms')
42
- }
43
- }
44
-
45
- static endOfName(name: string, microsecond?: boolean): void {
39
+ endOfName(name: string, microsecond?: boolean): void {
46
40
  const id = R.nameToIdMap[name]
47
41
  if (id !== undefined) R.end(id, microsecond)
48
42
  }
package/types/index.d.ts CHANGED
@@ -6,17 +6,16 @@ interface ids {
6
6
  interface names {
7
7
  [name: string]: string;
8
8
  }
9
- declare class Run {
10
- static currentId: number;
11
- static currentTime: number;
12
- static currentName: string;
13
- static idMap: ids;
14
- static nameMap: names;
15
- static nameToIdMap: ids;
16
- static start(name: string, microsecond?: boolean): number;
17
- static end(id: number, microsecond?: boolean): void;
18
- static endOfName(name: string, microsecond?: boolean): void;
19
- }
9
+ declare const Run: {
10
+ currentId: number;
11
+ currentName: string;
12
+ idMap: ids;
13
+ nameMap: names;
14
+ nameToIdMap: ids;
15
+ start(name: string, microsecond?: boolean): number;
16
+ end(id: number, microsecond?: boolean): void;
17
+ endOfName(name: string, microsecond?: boolean): void;
18
+ };
20
19
 
21
20
  declare class Debug {
22
21
  static enable: boolean;
@@ -32,6 +31,7 @@ declare class Debug {
32
31
  static set filter(name: string | string[]);
33
32
  static set exclude(name: string | string[]);
34
33
  log(...messages: unknown[]): void;
34
+ tip(...messages: unknown[]): void;
35
35
  warn(...messages: unknown[]): void;
36
36
  repeat(name: string, ...messages: unknown[]): void;
37
37
  error(...messages: unknown[]): void;