Skip to content

Instantly share code, notes, and snippets.

@dcporter
Created November 1, 2019 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcporter/2313eaf0b8fede468958ccbf2afcb6d6 to your computer and use it in GitHub Desktop.
Save dcporter/2313eaf0b8fede468958ccbf2afcb6d6 to your computer and use it in GitHub Desktop.
// A public observable
export const myObservable = RxJS.something(
// ?
);
// A function I can call any time to emit `val` from `myObservable`
function secretFunction(val) {
// ?
}
@awk
Copy link

awk commented Nov 1, 2019

const mySubject = new RxJS.Subject();

export function getMyObservable() {
  return mySubject.asObservable();
}

export function secretFunction(val) {
  mySubject.next(val);
}

// There's nothing up there to complete the subject - there should be a 'done' :
export function imDone() {
  mySubject.complete();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment