Skip to content

Commit 4772a14

Browse files
committed
Merge branch 'pull/26' (developit#26) into perf-adjustments
2 parents e425075 + d38d1b9 commit 4772a14

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

src/undom.js

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,32 @@ function createEnvironment() {
152152
}
153153

154154

155+
class Event {
156+
constructor(type, opts) {
157+
this.type = type;
158+
this.bubbles = !!(opts && opts.bubbles);
159+
this.cancelable = !!(opts && opts.cancelable);
160+
}
161+
stopPropagation() {
162+
this._stop = true;
163+
}
164+
stopImmediatePropagation() {
165+
this._end = this._stop = true;
166+
}
167+
preventDefault() {
168+
this.defaultPrevented = true;
169+
}
170+
}
171+
172+
155173
class Document extends Element {
156174
constructor() {
157175
super(9, '#document'); // DOCUMENT_NODE
176+
this.defaultView = new DefaultView(this);
177+
}
178+
179+
get document() {
180+
return this;
158181
}
159182

160183
createElement(type) {
@@ -167,37 +190,28 @@ function createEnvironment() {
167190
return element;
168191
}
169192

170-
171193
createTextNode(text) {
172194
return new Text(text);
173195
}
174196
}
175197

198+
assign(Document.prototype, { Document, Node, Text, Element, SVGElement: Element, Event });
176199

177-
class Event {
178-
constructor(type, opts) {
179-
this.type = type;
180-
this.bubbles = !!(opts && opts.bubbles);
181-
this.cancelable = !!(opts && opts.cancelable);
182-
}
183-
stopPropagation() {
184-
this._stop = true;
185-
}
186-
stopImmediatePropagation() {
187-
this._end = this._stop = true;
188-
}
189-
preventDefault() {
190-
this.defaultPrevented = true;
200+
201+
class DefaultView {
202+
constructor(document) {
203+
this.document = document;
191204
}
192205
}
193206

207+
assign(DefaultView.prototype, { Document, Node, Text, Element, SVGElement: Element, Event });
208+
194209

195210
/** Create a minimally viable DOM Document
196-
* @returns {Document} document
197-
*/
211+
* @returns {Document} document
212+
*/
198213
function createDocument() {
199214
let document = new Document();
200-
assign(document, document.defaultView = { document, Document, Node, Text, Element, SVGElement: Element, Event });
201215
document.appendChild(
202216
document.documentElement = document.createElement('html')
203217
);

0 commit comments

Comments
 (0)