UNPKG

@atlaskit/util-service-support

Version:

A library of support classes for integrating React components with REST HTTP services

42 lines 971 B
import _defineProperty from "@babel/runtime/helpers/defineProperty"; export class AbstractResource { constructor() { _defineProperty(this, "listeners", new Set()); } subscribe(onChange) { this.listeners.add(onChange); if (this.lastResult) { // Notify subscribe of last result (i.e. initial state) onChange.result(this.lastResult); } } unsubscribe(onChange) { this.listeners.delete(onChange); } notifyResult(result) { this.listeners.forEach(onChange => { onChange.result(result); }); } notifyError(error) { this.listeners.forEach(onChange => { if (onChange.error) { onChange.error(error); } }); } notifyInfo(info) { this.listeners.forEach(onChange => { if (onChange.info) { onChange.info(info); } }); } notifyNotReady() { this.listeners.forEach(onChange => { if (onChange.notReady) { onChange.notReady(); } }); } }