Skip to content

Commit

Permalink
feat: separate load and get logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ilfa committed Apr 7, 2023
1 parent 2a37df9 commit 188d2e8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
@@ -1,2 +1,2 @@
import { load } from './load'
export { load }
import { load, get } from './load'
export { load, get }
16 changes: 10 additions & 6 deletions src/load.ts
Expand Up @@ -2,12 +2,16 @@ import * as FingerprintJS from '@fingerprintjs/fingerprintjs-pro'
import { LoadOptions, GetOptions, GetResult } from '@fingerprintjs/fingerprintjs-pro'
import { addIntegrationInfo } from './integrationInfo'

export const load = (
loadOptions: LoadOptions,
getOptions: GetOptions<boolean>,
callback: (result: GetResult) => void
) => {
const fpPromise = FingerprintJS.load(addIntegrationInfo(loadOptions))
let fpPromise: Promise<FingerprintJS.Agent> | undefined

export const load = (loadOptions: LoadOptions, callback: () => void) => {
fpPromise = FingerprintJS.load(addIntegrationInfo(loadOptions))
fpPromise.then(() => callback())
}

export const get = (getOptions: GetOptions<boolean>, callback: (result: GetResult) => void) => {
if (!fpPromise) {
throw new Error('Call load method first')
}
fpPromise.then((fp) => fp.get(getOptions)).then((result) => callback(result))
}

0 comments on commit 188d2e8

Please sign in to comment.