Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 853 Bytes

no-exposed-subjects.md

File metadata and controls

39 lines (30 loc) · 853 Bytes

Avoid public and protected subjects (no-exposed-subjects)

This rule prevents the public or protected subjects. Developers should instead expose observables via the subjects' toObservable method.

Rule details

Examples of incorrect code for this rule:

import { Subject } from "rxjs";
class Answers {
  public answers: Subject<number>;
}

Examples of correct code for this rule:

import { Subject } from "rxjs";
class Answers {
  private _answers: Subject<string>;
  get answers() {
    return this._answers.toObservable();
  }
}

Options

This rule accepts a single option which is an object with an allowProtected property that determines whether or not protected subjects are allowed. By default, they are not.

{
  "rxjs/no-exposed-subjects": [
    "error",
    { "allowProtected": true }
  ]
}