Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat! (stores): ✨ Async Stores #129

Merged
merged 14 commits into from
Jul 12, 2023
Merged

feat! (stores): ✨ Async Stores #129

merged 14 commits into from
Jul 12, 2023

Conversation

whizzzkid
Copy link
Collaborator

@whizzzkid whizzzkid commented Jul 10, 2023

In this PR:

  • Introduced Async Stores.
  • These are needed for the ipfs-companion's async localstorage api, chrome.storage.local.get ...
  • Since this now supports async stores, the property initDone is now public.
  • Fixed types being exported in the public dist, i.e. dist refers to types from ../types/index.d.ts but it's not actually shipped. Added a typings folder and moved the shared types to .ts file, which fixes this (tsc does not touch .d.ts files)
  • Introducing this as a breaking change as this might break existing refs.

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Copy link
Collaborator Author

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-review.

@@ -22,7 +22,6 @@ dist/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
typings/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷🏽 Is this an issue 🤔


export class BrowserStorageProvider implements StorageProvider {
export class BrowserStorageProvider implements StorageProviderInterface {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes it simpler to understand what the interface looks like, otherwise the type changes when we add methods to StorageProvider

@@ -20,8 +20,9 @@ export interface MetricsProviderConstructorOptions<T> {
metricsService: T
queue_size?: number
session_update?: number
storage?: 'none' | 'localStorage' | 'sessionStorage' | 'cookie'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private readonly storageProvider: StorageProvider | null
private readonly initDone: boolean = false
private readonly storageProvider: StorageProviderInterface | null
public initDone: boolean = false
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now needs to be checked.

@@ -58,9 +59,13 @@ export default class MetricsProvider<T extends CountlyWebSdk | CountlyNodeSdk> {
this.setupAutoTrack()
}

const existingConsent = this.getConsentStore()
void this.initExistingConsent()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because this call is now async.

tsconfig.json Outdated
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just auto-fixed 😵‍💫

Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Signed-off-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
private readonly storageProvider: StorageProvider | null
private readonly initDone: boolean = false
private readonly storageProvider: StorageProviderInterface | null
public initDone: boolean = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should probably add _initDone and make initDone a function that returns a promise.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with us handling this later.

Comment on lines 123 to 125
while (!telemetry.initDone) {
await new Promise(resolve => setTimeout(resolve, 10))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big fan of needing a while loop, but im okay with it for now.

Can we add a followup action item for exposing a promise that folks can await to determine when init is done?

private readonly storageProvider: StorageProvider | null
private readonly initDone: boolean = false
private readonly storageProvider: StorageProviderInterface | null
public initDone: boolean = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public initDone: boolean = false
public initDone: Promise<boolean> = false

@@ -58,9 +62,13 @@ export default class MetricsProvider<T extends CountlyWebSdk | CountlyNodeSdk> {
this.setupAutoTrack()
}

const existingConsent = this.getConsentStore()
void this.initExistingConsent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
void this.initExistingConsent()
this.initDone = this.initExistingConsent()

@whizzzkid whizzzkid merged commit 4abe722 into main Jul 12, 2023
15 checks passed
@github-actions
Copy link

🎉 This PR is included in version 2.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants