@exceptionless/fetchclient
Version:
A simple fetch client with middleware support for Deno and the browser.
41 lines (40 loc) • 989 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Counter = void 0;
const ObjectEvent_js_1 = require("./ObjectEvent.js");
/**
* Represents a counter that can be incremented and decremented.
*/
class Counter {
#count = 0;
#onChange = new ObjectEvent_js_1.ObjectEvent();
/**
* Gets the current count.
*/
get count() {
return this.#count;
}
/**
* Gets an event that is triggered when the count changes.
*/
get changed() {
return this.#onChange.expose();
}
/**
* Increments the count by 1.
*/
increment() {
const previous = this.#count;
this.#count++;
this.#onChange.trigger({ previous, value: this.#count });
}
/**
* Decrements the count by 1.
*/
decrement() {
const previous = this.#count;
this.#count--;
this.#onChange.trigger({ previous, value: this.#count });
}
}
exports.Counter = Counter;