@threlte/theatre
Version:
Threlte Components for Theatre, an animation library with a professional motion design toolset
23 lines (22 loc) • 663 B
JavaScript
import { getContext } from 'svelte';
// hook
export function createSheetObjectAction() {
// get sheet from context
const sheet = getContext('theatre-sheet').sheet;
// create object action
return (node, { key, props, callback, options = { reconfigure: true } }) => {
// create object
const obj = sheet.object(key, props, options);
// callback reactivity
const unsubscribe = obj.onValuesChange((obj) => {
callback(node, obj);
});
// disposal
return {
destroy() {
unsubscribe();
sheet.detachObject(key);
}
};
};
}