-
Notifications
You must be signed in to change notification settings - Fork 21
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
[ts-sdk] Add offline processing #880
Conversation
993b69e
to
91a2cd5
Compare
91a2cd5
to
92478b7
Compare
<Show delayMs={2000}> | ||
<InputTile inputId="input_2" /> | ||
</Show> | ||
<Show timestampMs={{ start: 5000, end: 8000 }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either <Show timeRange={{ start: 5000, end: 8000 }}>
or <Show timeRangeMs={{ start: 5000, end: 8000 }}>
, but I prefer the first one - I'm not sure if that many libraries specify the unit in the props in this manner. You can usually safely assume that it's ms.
return ( | ||
<Tiles transition={{ durationMs: 200 }}> | ||
<InputTile inputId="input_1" /> | ||
<Show delayMs={2000}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd only remove the unit to unify it with the timestamp, if necessary
|
||
function ExampleApp() { | ||
return ( | ||
<Tiles transition={{ durationMs: 200 }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd only remove the unit to unify it with the timestamp, if necessary
|
||
export type ShowProps = { | ||
timestampMs?: { start?: number; end?: number }; | ||
delayMs?: number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with delay
class UpdateTracker { | ||
private promise: Promise<void> = new Promise(() => {}); | ||
private promiseRes: () => void = () => {}; | ||
private updateTimeout: number = -1; | ||
private renderTimeout: number = -1; | ||
|
||
constructor() { | ||
this.promise = new Promise((res, _rej) => { | ||
this.promiseRes = res; | ||
}); | ||
} | ||
|
||
public onUpdate() { | ||
clearTimeout(this.updateTimeout); | ||
this.updateTimeout = setTimeout(() => { | ||
this.promiseRes(); | ||
}, MAX_NO_UPDATE_TIMEOUT_MS); | ||
} | ||
|
||
public async waitForRenderEnd(): Promise<void> { | ||
this.promise = new Promise((res, _rej) => { | ||
this.promiseRes = res; | ||
}); | ||
clearTimeout(this.renderTimeout); | ||
this.renderTimeout = setTimeout(() => { | ||
console.warn( | ||
"Render for a specific timestamp took too long, make sure you don't have infinite update loop." | ||
); | ||
this.promiseRes(); | ||
}, MAX_RENDER_TIMEOUT_MS); | ||
await this.promise; | ||
clearTimeout(this.renderTimeout); | ||
clearTimeout(this.updateTimeout); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand the flow here.
waitForRenderEnd()
waits forthis.promiseRes()
to be called. Which is called in 2 cases:updateTimeout
is executed first, orrenderTimeout
is executed first
I don't see any situation where this.promiseRes
is called outside of those timeouts. Is that how it's supposed to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this mechanism is similar in the idea to throttling. We want to send an update when we know that onUpdate was not called for 20ms. The second time limit (renderTimeout
) is to just protect against some infinite loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
92478b7
to
19706fd
Compare
Api changes
Slides
/Slide
componentsShow
componentuseAfterTimestamp
hook (internally used byShow
)useCurrentTimestamp
returns the current timestamp (does not trigger re-render for every time change)useAfterTimestamp
return the current timestamp (and maybe change name of that hook)useBlockingTask
hooknewBlockingTask
function prrivate (internal implementation ofuseBlockingTask
)TimeContext
object. (newBlockingTask needs the context as argument)useBlockingTaskBuilder
that returns a function to start a new blocking task.useTimeLimitedComponent
.InputStream
orMp4
components. It is public for now, so we can write some examples and test internalls.TODO in follow up
Currently, there are no components that support automatic slide change. I'm planning to add