UNPKG

@playcanvas/react

Version:

A React renderer for PlayCanvas – build interactive 3D applications using React's declarative paradigm.

45 lines 1.63 kB
export function createInstance(type, props, app) { if (!app.systems[type]) { throw new Error(`Invalid component type: '${type}'`); } return { type: 'component', componentType: type, componentData: props, componentProps: props, attachedTo: null, }; } export function commitUpdate(instance, _type, _oldProps, newProps) { console.log('commitUpdate', instance, _type, _oldProps, newProps); const { attachedTo: entity, componentType } = instance; if (!entity) { throw new Error('Component is not attached to an entity'); } // @ts-ignore const comp = entity[componentType]; Object.assign(comp, newProps); } export function appendChild(parent, child) { if (parent.type === 'entity' && child.type === 'component') { // @ts-ignore if (!parent.entity[child.componentType]) { parent.entity.addComponent(child.componentType, { ...child.componentProps }); } child.attachedTo = parent.entity; commitUpdate(child, 'component', {}, child.componentProps); } } export function appendInitialChild(parent, child) { appendChild(parent, child); } export function removeChild(parent, child) { parent.entity.removeComponent(child.componentType); child.attachedTo = null; } // export function removeChildFromContainer(container: PlayCanvasHostContext, child: ComponentNode) { // } export function appendChildToContainer(_container, _child) { console.warn('Cannot attach a component directly to the root. Wrap it in an <Entity>.'); } //# sourceMappingURL=component-config.js.map