Skip to content

Instantly share code, notes, and snippets.

@bkardell
Last active August 29, 2015 13:55
Show Gist options
  • Save bkardell/8742746 to your computer and use it in GitHub Desktop.
Save bkardell/8742746 to your computer and use it in GitHub Desktop.

Has something really simple like actually exposing the render tree in some basic ways ever been proposed?

For example, what if there were an object called

css.renderTree;

And it just had a couple of static methods...

class CSSRenderTree {

	/* See CSSRenderObject below */
	static root;

	/* Given an element, provides its generated render object */
	static getAssociatedRenderObject(el);

	/* See CSSRenderObject below */
	static getRenderObjectByName(str);
}

....And that just exposed a really simple Node interface (which actually is magic that already exists - right?)

class CSSRenderObject {

	public children: [];
	public parent;
	public index;
	public name;

	/* basic tree stuff */
	public firstChild() { ... }
	public lastChild() { ... }
	public previousSibling() { ... }
	public nextSibling() { ... }
	public appendChild() { ... }
	public insertBefore() { ... }
	public removeChild() { ... }
	public replaceChild() { ... }

	/* That's kinda all you really need, right? */
	public markDirty(?children) { ... }
	public setStyle({style});

        constructor(?element, ?name) {
            // Seems straighforward...
             // Handy to make it constructable with an element... 
             // That's existing magic, right? 
             // Also handy if it can have a name for 
             // retrieval since it may have no relationship
             // with DOM in the tree
         }

}

class CSSBox extends CSSRenderObject {
	
}

Then, in theory, we could really actually experiment a whole lot, right? What's wrong with that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment