Files
gerrit/polygerrit-ui/app/services
Ben Rohlfs 57d7a814ea Add selection of check run chips
We don't do anything with the selection yet. This is just about
introducing the model and the styling for now.

https://imgur.com/a/5uA5Qtg

Change-Id: Id82431e806456e72903e518b016e17697dbbd631
2021-02-09 14:24:24 +01:00
..
2021-02-09 14:24:24 +01:00
2020-11-10 16:15:30 +00:00
2021-01-21 10:05:45 +01:00
2020-04-21 09:57:12 +02:00

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
}