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

Class MainDOMSource

dom/src/MainDOMSource.ts:87–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87export class MainDOMSource implements DOMSource {
88
89 constructor(private _rootElement$: Stream<Element>,
90 private _sanitation$: Stream<null>,
91 private _namespace: Array<string> = [],
92 public _isolateModule: IsolateModule,
93 public _delegators: Map<string, EventDelegator>,
94 private _name: string) {
95 this.isolateSource = isolateSource;
96 this.isolateSink = (sink, scope) => {
97 const prevFullScope = getFullScope(this._namespace);
98 const nextFullScope = [prevFullScope, scope].filter(x => !!x).join('-');
99 return internalIsolateSink(sink, nextFullScope) as Stream<VNode>;
100 };
101 }
102
103 public elements(): MemoryStream<Element> {
104 let output$: Stream<Element | Array<Element>>;
105 if (this._namespace.length === 0) {
106 output$ = this._rootElement$;
107 } else {
108 const elementFinder = new ElementFinder(this._namespace, this._isolateModule);
109 output$ = this._rootElement$.map(el => elementFinder.call(el));
110 }
111 const out: DevToolEnabledSource & MemoryStream<Element> = adapt(output$.remember());
112 out._isCycleSource = this._name;
113 return out;
114 }
115
116 get namespace(): Array<string> {
117 return this._namespace;
118 }
119
120 public select(selector: string): DOMSource {
121 if (typeof selector !== 'string') {
122 throw new Error(`DOM driver's select() expects the argument to be a ` +
123 `string as a CSS selector`);
124 }
125 if (selector === 'document') {
126 return new DocumentDOMSource(this._name);
127 }
128 if (selector === 'body') {
129 return new BodyDOMSource(this._name);
130 }
131 const trimmedSelector = selector.trim();
132 const childNamespace = trimmedSelector === `:root` ?
133 this._namespace :
134 this._namespace.concat(trimmedSelector);
135 return new MainDOMSource(
136 this._rootElement$,
137 this._sanitation$,
138 childNamespace,
139 this._isolateModule,
140 this._delegators,
141 this._name,
142 );
143 }
144

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected