Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further improve performance of Document creation. #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions src/undom.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,32 @@ class Element extends Node {
}


class Event {
constructor(type, opts) {
this.type = type;
this.bubbles = !!(opts && opts.bubbles);
this.cancelable = !!(opts && opts.cancelable);
}
stopPropagation() {
this._stop = true;
}
stopImmediatePropagation() {
this._end = this._stop = true;
}
preventDefault() {
this.defaultPrevented = true;
}
}


class Document extends Element {
constructor() {
super(9, '#document'); // DOCUMENT_NODE
this.defaultView = new DefaultView(this);
}

get document() {
return this;
}

createElement(type) {
Expand All @@ -166,37 +189,28 @@ class Document extends Element {
return element;
}


createTextNode(text) {
return new Text(text);
}
}

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

class Event {
constructor(type, opts) {
this.type = type;
this.bubbles = !!(opts && opts.bubbles);
this.cancelable = !!(opts && opts.cancelable);
}
stopPropagation() {
this._stop = true;
}
stopImmediatePropagation() {
this._end = this._stop = true;
}
preventDefault() {
this.defaultPrevented = true;

class DefaultView {
constructor(document) {
this.document = document;
}
}

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


/** Create a minimally viable DOM Document
* @returns {Document} document
*/
export default function createDocument() {
let document = new Document();
assign(document, document.defaultView = { document, Document, Node, Text, Element, SVGElement: Element, Event });
document.appendChild(
document.documentElement = document.createElement('html')
);
Expand Down