Skip to content

Replace k6StudioState global variable in main process #634

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

Open
cristianoventura opened this issue Apr 8, 2025 · 0 comments
Open

Replace k6StudioState global variable in main process #634

cristianoventura opened this issue Apr 8, 2025 · 0 comments
Labels
refactor This issue is related to improvement in code refactoring

Comments

@cristianoventura
Copy link
Collaborator

NOTE: This issue depends on #378 to be completed.

When splitting the main.ts file, we introduced a global object in the main process called k6StudioState. This object contains variables that are used/mutated for multiple IPC handlers and is accessible anywhere in the main process.

Once #378 is complete, we'd like to replace that global variable with a more robust approach that allows the currently global variables to be injected into the handlers. See proposal in #627 (comment)

Example:

interface ProxyServiceEvents {
  'status:change': [ProxyStatus],
  ready: [void]
}

export class ProxyService extends EventEmitter<ProxyServiceEvents> {
  status: ProxyStatus
  
  start() {}
  stop() {}
}

// handlers/index.ts
export function initialize({ browserServer, proxyService }: Services) {
  browserRemote.initialize(browserServer);
  
  // Right now the `browser` handler parts are actually using a global
  // variable because I didn't want to rewrite that part. But this is what
  // it will look like after this PR is merged.
  browser.initialize(browserServer, proxyService)
}
@cristianoventura cristianoventura added the refactor This issue is related to improvement in code refactoring label Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor This issue is related to improvement in code refactoring
Projects
None yet
Development

No branches or pull requests

1 participant