-
Notifications
You must be signed in to change notification settings - Fork 173
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
async/ non-blocking tween calculation #116
Comments
This feature is real cool indeed, just I don't have the time to develop. |
understandable :) i dont have time to dig through this package, but i managed to tuck together an interface.tsexport interface TweenResultMessage {
error?: String;
data?: KUTE.Tween;
}
export interface TweenInputMessage {
elem: Element;
from: KUTE.tweenProps;
to: KUTE.tweenProps;
opts?: KUTE.tweenOptions;
} morphWorker.tsimport KUTE from 'kute.js';
import type {TweenInputMessage, TweenResultMessage} from './interface';
onmessage = (e:MessageEvent<TweenInputMessage>):void => {
const {elem, from, to, opts} = e.data;
try {
const tween = KUTE.fromTo(elem, from, to, opts)
postMessage({data: tween} as TweenResultMessage);
} catch (error) {
postMessage({error} as TweenResultMessage);
}
};
export {}; KUTEAsync.tsimport TweenCalculationWorker from "./morphWorker?worker";
import type {TweenInputMessage, TweenResultMessage} from './interface';
import type KUTE from "kute.js";
const fromToAsync = (elem:Element, from:KUTE.tweenProps, to:KUTE.tweenProps, opts:KUTE.tweenOptions):Promise<KUTE.Tween> => {
const worker = new TweenCalculationWorker();
worker.postMessage({elem, from, to, opts} as TweenInputMessage);
return new Promise((resolve, reject) => {
worker.onmessage = (e:MessageEvent<TweenResultMessage>) => {
const m = e.data;
if (m.error) reject(m.error);
else resolve(m.data);
}
});
}
export default {fromToAsync}; Usageimport KUTEA from 'KUTEAsync'
const tween = await KUTEA.fromToAsync(...args); maybe someone in this future can use this as a basis to actually implement this in KUTE |
Wow you are awesome! Thanks for that! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
since the tween calculation is very slow, it would be nice if it was async, ran in another web-worker
The text was updated successfully, but these errors were encountered: