-
Notifications
You must be signed in to change notification settings - Fork 15
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
renderToNode (or renderToElement) #15
Comments
Sorry, but I do not understand how this is related to How I see your code should look like: // app.js
import { h } from 'hyperapp'
export const state = {
sources: [/*...*/]
}
export const actions = {
onVideoLoad() {/*...*/},
onVideoAbort() {/*...*/},
onVideoWaiting() {/*...*/},
onVideoMeta() {/*...*/},
}
export const view = (state, actions) => (
<video
onloadeddata={actions.onVideoLoad}
onabort={actions.onVideoAbort}
onwaiting={actions.onVideoWaiting}
onloadedmetadata={actions.onVideoMeta}
preload="metadata"
muted="true"
playsinline="true"
>
{state.sources.map((source) => (
<source key={source.url} src={source.url} type={source.type} />
))}
</video>
) // client.js
import { app } from 'hyperapp'
import { state, actions, view } from './app'
app(state, actions, view, document.getElementById('app')) // server.js
import http from 'http'
import { renderToString } from 'hyperapp-render'
import { state, actions, view } from './app'
http.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html')
res.end(renderToString(
<html>
<head><title>Video</title></head>
<body>
<div id="app">{view(state, actions)}</div>
</body>
</html>
))
}).listen(8080) P.S.: You can use |
I can hide those elements or put outside browser view box, but it is huge slowdown, ui freeze and sometimes browser crash when you have many high resolution images and videos on page. When browser already loaded data from videos and images, everything goes smooth. Why So, my example will look like this: // client.js
import { app } from 'hyperapp'
import { state, actions, view, preloadVideo } from './app'
app(state, actions, view, document.getElementById('app'))
const appData = {
videos: [{
sources: [{
url: "1.mp4",
type: "video/mp4"
}, {
url: "1.webm",
type: "video/webm"
}]
}]
};
// This should work as part of subscription, but I still learning how to do that
Promise.all (appData.videos.map (v => preloadVideo(v))).then (videoEvents => {
// browser will load one of videos by type:
// safari for mac and ios + ie will load h.264
// chrome + ff will load webm
// but currentSrc will definitely contain playable video
changeState (state => (videos: videoEvents.map (event => event.target.currentSrc)))
})
// app.js
import { h } from 'hyperapp'
export const state = {
videos: []
}
export const actions = {
onVideoLoad() {/*...*/},
onVideoAbort() {/*...*/},
onVideoWaiting() {/*...*/},
onVideoMeta() {/*...*/},
}
export const view = (state, actions) => (
<video
onloadeddata={actions.onVideoLoad}
onabort={actions.onVideoAbort}
onwaiting={actions.onVideoWaiting}
onloadedmetadata={actions.onVideoMeta}
preload="metadata"
muted="true"
playsinline="true"
>
{state.sources.map((source) => (
<source key={source.url} src={source.url} type={source.type} />
))}
</video>
)
export function preloadVideo (videoParams) {
return new Promise ((resolve, reject) => {
const videoEl = renderElement(<video
onloadeddata={resolve}
preload="metadata"
muted="true"
playsinline="true"
>
{state.sources.map((source) => (
<source key={source.url} src={source.url} type={source.type} />
))}
</video>);
videoEl.load()
});
} |
I still do not see why/how you use import { app, h } from 'hyperapp'
const state = {
videoIsReadyToRender: false
}
const actions = {
load() {
// (pre)load video here
return { videoIsReadyToRender: true }
}
}
const view = (state, actions) => (
<div onload={actions.load}>
{state.videoIsReadyToRender ? <YourVideo /> : <b>Loading video...</b>}
</div>
)
app(state, actions, view, document.body) |
😁Let's go to Slack and discuss in chat mode quickly (my nickname is |
Hi,
I'm submitting a ...
Within hyperapp sometimes I need to make some preparations, to ensure everything is going fine with DOM/events/data. For example:
<video>
element, append some sources, and check which one browser wants to load;<img>
element and check if image is accessible and what size they have;svg
fragment into already loaded though<object>
tagsvg
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 likeI can implement it myself and make a pull request if you're interested in this.
The text was updated successfully, but these errors were encountered: