MCPcopy Create free account
hub / github.com/cyclejs/cyclejs / events

Method events

dom/src/MainDOMSource.ts:145–201  ·  view source on GitHub ↗
(eventType: string, options: EventsFnOptions = {})

Source from the content-addressed store, hash-verified

143 }
144
145 public events(eventType: string, options: EventsFnOptions = {}): Stream<Event> {
146 if (typeof eventType !== `string`) {
147 throw new Error(`DOM driver's events() expects argument to be a ` +
148 `string representing the event type to listen for.`);
149 }
150 const useCapture: boolean = determineUseCapture(eventType, options);
151
152 const namespace = this._namespace;
153 const fullScope = getFullScope(namespace);
154 const keyParts = [eventType, useCapture];
155 if (fullScope) {
156 keyParts.push(fullScope);
157 }
158 const key = keyParts.join('~');
159 const domSource = this;
160
161 let rootElement$: Stream<Element>;
162 if (fullScope) {
163 rootElement$ = this._rootElement$
164 .compose(filterBasedOnIsolation(domSource, fullScope));
165 } else {
166 rootElement$ = this._rootElement$.take(2);
167 }
168
169 const event$: Stream<Event> = rootElement$
170 .map(function setupEventDelegatorOnTopElement(rootElement) {
171 // Event listener just for the root element
172 if (!namespace || namespace.length === 0) {
173 return fromEvent(rootElement, eventType, useCapture);
174 }
175
176 // Event listener on the origin element as an EventDelegator
177 const delegators = domSource._delegators;
178 const origin = domSource._isolateModule.getElement(fullScope) || rootElement;
179 let delegator: EventDelegator;
180 if (delegators.has(key)) {
181 delegator = delegators.get(key) as EventDelegator;
182 delegator.updateOrigin(origin);
183 } else {
184 delegator = new EventDelegator(
185 origin, eventType, useCapture, domSource._isolateModule,
186 );
187 delegators.set(key, delegator);
188 }
189 if (fullScope) {
190 domSource._isolateModule.addEventDelegator(fullScope, delegator);
191 }
192
193 const subject = delegator.createDestination(namespace);
194 return subject;
195 })
196 .flatten();
197
198 const out: DevToolEnabledSource & Stream<Event> = adapt(event$);
199 out._isCycleSource = domSource._name;
200 return out;
201 }
202

Callers

nothing calls this directly

Calls 11

getFullScopeFunction · 0.90
fromEventFunction · 0.90
adaptFunction · 0.90
determineUseCaptureFunction · 0.85
filterBasedOnIsolationFunction · 0.85
getElementMethod · 0.80
hasMethod · 0.80
updateOriginMethod · 0.80
addEventDelegatorMethod · 0.80
createDestinationMethod · 0.80
mapMethod · 0.65

Tested by

no test coverage detected