tree: c1a229c91febebfc6b8a68453ef9b5d959505c62 [path history] [tgz]
  1. change/
  2. checks/
  3. comments/
  4. config/
  5. flags/
  6. gr-auth/
  7. gr-event-interface/
  8. gr-reporting/
  9. gr-rest-api/
  10. router/
  11. storage/
  12. user/
  13. app-context-init.ts
  14. app-context-init_test.js
  15. app-context.ts
  16. README.md
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 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 appContext especially in static methods.

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

class T {
  constructor() {
    super();
    this.flagsService = appContext.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 {appContext} from '../../../services/app-context.js';

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