Skip to content

renderToNode (or renderToElement) #15

@apla

Description

@apla

Hi,

I'm submitting a ...

  • bug report
  • feature request
  • other (Please do not submit support requests here (below))

Within hyperapp sometimes I need to make some preparations, to ensure everything is going fine with DOM/events/data. For example:

  1. generate <video> element, append some sources, and check which one browser wants to load;
  2. create <img> element and check if image is accessible and what size they have;
  3. insert svg fragment into already loaded though <object> tag svg dom.

It is really useful to have function, which renders h('video', ...) into new Element, which can be inserted into existing DOM or just loaded (like images or videos), because as of now my preparations looks like

const el = document.createElement('video');
el.addEventListener('loadeddata', this.onVideoLoad.bind(this), false);
el.addEventListener('abort', this.onVideoAbort.bind(this), false);
el.addEventListener('waiting', this.onVideoWaiting.bind(this), false);
el.addEventListener('loadedmetadata', this.onVideoMeta.bind (this), false);
el.setAttribute('preload', 'metadata');
el.setAttribute('muted', 'true');
el.setAttribute('playsinline', 'true');
this.config.sources.forEach(source => {
	var srcEl = document.createElement('source');
	srcEl.src = patchLocalVideo(source.url);
	srcEl.type = source.type;
	el.appendChild(srcEl);
});

I can implement it myself and make a pull request if you're interested in this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions