tree: cd125a238be477b0f915191bb33969443efad01a [path history] [tgz]
  1. flags/
  2. gr-auth/
  3. gr-event-interface/
  4. gr-reporting/
  5. gr-rest-api/
  6. highlight/
  7. router/
  8. scheduler/
  9. shortcuts/
  10. storage/
  11. app-context-init.ts
  12. app-context-init_test.ts
  13. app-context.ts
  14. README.md
  15. registry.ts
  16. registry_test.ts
  17. service-worker-installer.ts
  18. service-worker-installer_test.ts
polygerrit-ui/app/services/README.md

What is services folder

‘services’ folder contains services used across multiple components.

What should be considered as services in Gerrit UI

Services should be stateful, if its just pure functions, consider having them in ‘utils’ instead.

Regarding all stateful should be considered as services or not, it‘s still TBD. Will update as soon as it’s finalized.

How to access a service

We use AppContext to access instance of service. It helps in mocking service in tests as well. We prefer setting instance of service in constructor and then accessing it from variable. We also allow access straight from getAppContext() especially in static methods.

import {getAppContext()} from '../../../services/app-context.js';

class T {
  private readonly flagsService = getAppContext().flagsService;

  action1() {
    if (this.flagsService.isEnabled('test)) {
      // do something
    }
  }
}

staticMethod() {
  if (appContext.flagsService.isEnabled('test)) {
    // do something
  }
}

What services we have

Flags

‘flags’ is a service to provide easy access to all enabled experiments.

import {getAppContext} from '../../../services/app-context.js';

// check if an experiment is enabled or not
if (getAppContext().flagsService.isEnabled('test')) {
  // do something
}