UNPKG

@foundatiofx/fetchclient

Version:

A typed JSON fetch client with middleware support for Deno, Node and the browser.

37 lines (36 loc) 843 B
import { ObjectEvent } from "./ObjectEvent.js"; /** * Represents a counter that can be incremented and decremented. */ export class Counter { #count = 0; #onChange = new 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 }); } }