Eventable
Eventable is the event-system mixin factory of maptalks. It gives a host class full on/off/once/fire event capabilities. It is not instantiated on its own; instead it is merged into other classes (such as Map, GroupLayer) via Class.include(Eventable) or a similar mechanism, so those classes can listen for, dispatch, and manage events.
js
import { Eventable } from "maptalks";
class MyThing extends Eventable(Class) { /* ... */ }
const thing = new MyThing();
thing.on("click", () => console.log("clicked"));
thing.fire("click");
thing.off("click", () => console.log("clicked"));Constructor
Mixin factory — no independent constructor. The host class gains event capability automatically after construction.
options
No independent configuration options. Event behavior is governed by the host class's own options.
Methods
on(events, handler, context?)— Register a listener for the given event(s).eventsmay be a single event name or space-separated names;handleris the callback;contextoptionally sets thethisfor the callback.addEventListener(events, handler, context?)— Alias ofon.off(events, handler, context?)— Remove an event listener, matched by event name andhandler; ifhandleris omitted, no listeners are removed.removeEventListener(events, handler, context?)— Alias ofoff.once(events, handler, context?)— Register a listener that fires only once, then removes itself.listens(eventType, handler?, context?)— Whether a listener exists for the given event; withhandler, checks whether that exact callback is listened to.getListeningEvents()— Return all registered events and their listeners of the instance.copyEventListeners(target)— Copy this instance's listeners onto thetargetobject.fire(eventType, param?)— Dispatch (fire) an event of the given type, passingparamas the event data to listeners.
Static Methods
None.
Events
Concrete events are fired by the host class. The event types raised by fire() are what listeners receive.