Skip to content

Commit

Permalink
refactor types to be more DRY (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
silesky authored Oct 24, 2022
1 parent 525705f commit de11054
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/browser/src/core/analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { version } from '../../generated/version'
import { PriorityQueue } from '../../lib/priority-queue'
import { getGlobal } from '../../lib/get-global'
import { inspectorHost } from '../inspector'
import { AnalyticsClassic, AnalyticsSnippetCore } from './interfaces'
import { AnalyticsClassic, AnalyticsCore } from './interfaces'

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

export class Analytics
extends Emitter
implements AnalyticsSnippetCore, AnalyticsClassic
implements AnalyticsCore, AnalyticsClassic
{
protected settings: AnalyticsSettings
private _user: User
Expand Down
20 changes: 6 additions & 14 deletions packages/browser/src/core/analytics/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ export interface AnalyticsClassic extends AnalyticsClassicStubs {
}

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

/**
* Interface implemented by AnalyticsBrowser
* Interface implemented by AnalyticsBrowser (buffered version of analytics) (commonly accessible through AnalyticsBrowser.load())
*/
export interface AnalyticsBrowserCore {
track: AnalyticsSnippetCore['track']
page: AnalyticsSnippetCore['page']
identify: AnalyticsSnippetCore['identify']
group(): Promise<Group> // Different than AnalyticsSnippetCore ^
export type AnalyticsBrowserCore = Omit<AnalyticsCore, 'group' | 'user'> & {
group(): Promise<Group>
group(...args: UserParams): Promise<DispatchedEvent>
alias: AnalyticsSnippetCore['alias']
screen: AnalyticsSnippetCore['screen']
register: AnalyticsSnippetCore['register']
deregister: AnalyticsSnippetCore['deregister']
user(): Promise<User> // Different than AnalyticsSnippetCore ^
readonly VERSION: AnalyticsSnippetCore['VERSION']
user(): Promise<User>
}

0 comments on commit de11054

Please sign in to comment.