public off()

in libs/@guardian/identity-auth/src/emitter.ts [65:87]


	public off(name: EventName, callback?: EventCallback): this {
		// get the events object
		const events = this.#events;
		// get the event array for the event name
		const eventArr = events[name];
		// create an array to hold the current live events
		const liveEvents: Event[] = [];

		// if there is an event array, filter out the callback
		if (eventArr && callback) {
			liveEvents.push(...eventArr.filter((event) => event.fn !== callback));
		}

		// if there are live events, set them to the event name, otherwise delete the event name
		if (liveEvents.length) {
			events[name] = liveEvents;
		} else {
			delete events[name];
		}

		// return the emitter for chaining purposes
		return this;
	}