Skip to content

Commit de11054

Browse files
authored
refactor types to be more DRY (#617)
1 parent 525705f commit de11054

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

packages/browser/src/core/analytics/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import { version } from '../../generated/version'
3737
import { PriorityQueue } from '../../lib/priority-queue'
3838
import { getGlobal } from '../../lib/get-global'
3939
import { inspectorHost } from '../inspector'
40-
import { AnalyticsClassic, AnalyticsSnippetCore } from './interfaces'
40+
import { AnalyticsClassic, AnalyticsCore } from './interfaces'
4141

4242
const deprecationWarning =
4343
'This is being deprecated and will be not be available in future releases of Analytics JS'
@@ -84,7 +84,7 @@ function _stub(this: never) {
8484

8585
export class Analytics
8686
extends Emitter
87-
implements AnalyticsSnippetCore, AnalyticsClassic
87+
implements AnalyticsCore, AnalyticsClassic
8888
{
8989
protected settings: AnalyticsSettings
9090
private _user: User

packages/browser/src/core/analytics/interfaces.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ export interface AnalyticsClassic extends AnalyticsClassicStubs {
7272
}
7373

7474
/**
75-
* Interface implemented by the snippet ('Analytics')
75+
* Interface implemented by concrete Analytics class (commonly accessible if you use "await" on AnalyticsBrowser.load())
7676
*/
77-
export interface AnalyticsSnippetCore {
77+
export type AnalyticsCore = {
7878
track(...args: EventParams): Promise<DispatchedEvent>
7979
page(...args: PageParams): Promise<DispatchedEvent>
8080
identify(...args: UserParams): Promise<DispatchedEvent>
@@ -89,18 +89,10 @@ export interface AnalyticsSnippetCore {
8989
}
9090

9191
/**
92-
* Interface implemented by AnalyticsBrowser
92+
* Interface implemented by AnalyticsBrowser (buffered version of analytics) (commonly accessible through AnalyticsBrowser.load())
9393
*/
94-
export interface AnalyticsBrowserCore {
95-
track: AnalyticsSnippetCore['track']
96-
page: AnalyticsSnippetCore['page']
97-
identify: AnalyticsSnippetCore['identify']
98-
group(): Promise<Group> // Different than AnalyticsSnippetCore ^
94+
export type AnalyticsBrowserCore = Omit<AnalyticsCore, 'group' | 'user'> & {
95+
group(): Promise<Group>
9996
group(...args: UserParams): Promise<DispatchedEvent>
100-
alias: AnalyticsSnippetCore['alias']
101-
screen: AnalyticsSnippetCore['screen']
102-
register: AnalyticsSnippetCore['register']
103-
deregister: AnalyticsSnippetCore['deregister']
104-
user(): Promise<User> // Different than AnalyticsSnippetCore ^
105-
readonly VERSION: AnalyticsSnippetCore['VERSION']
97+
user(): Promise<User>
10698
}

0 commit comments

Comments
 (0)