pex-renderer icon indicating copy to clipboard operation
pex-renderer copied to clipboard

Component namespacing

Open vorg opened this issue 2 years ago • 6 comments

I miss destructuring a bit

const { components: { lights: { directional: directionalLight } } } = 
require("pex-renderer")

Any preference?

  1. (current)
import {
  components,  
} from "pex-renderer";

const e = {
  directionalLight: components.directionalLight()
}
import {
  components,  
} from "pex-renderer";

const lights = components.lights

const e = {
  directionalLight: components.light.directional()
}
import {
  directional as directionalLight,  
} from "pex-renderer/components/lights/directional.js";

const lights = components.lights

const e = {
  directionalLight: directionalLight()
}

vorg avatar Aug 04 '22 09:08 vorg

I would avoid 3. (deep import in packages currently cause me more headache and might confuse bundlers), keep pex-renderer exporting components and rely on tree-shaking.

Not sure it is necessary to sub-namespace components so I'd stick with 1.

dmnsgn avatar Aug 04 '22 09:08 dmnsgn

@simonharrisco mentions option 4. - exposing all components on the top level, also not a bad idea

import { directionalLight } from "pex-renderer"

const e = {
  directionalLight: directionalLight()
}

vorg avatar Aug 04 '22 09:08 vorg

  1. could simplify export in index.js:
export { default as directionalLight } from "./components/directional-light.js";
// or
export * from "./components/index.js";

and also means only systems are namespaced?

dmnsgn avatar Aug 04 '22 10:08 dmnsgn

and also means only systems are namespaced?

No, if we move components up then systems too.

vorg avatar Aug 04 '22 12:08 vorg

and also means only systems are namespaced?

No, if we move components up then systems too.

We'd run into conflict for animation (both component and system) unless systems are suffixed (animationSystem).

dmnsgn avatar Aug 04 '22 12:08 dmnsgn

Well that was the idea for name-spacing in the first place which looks like brings us back to current option 1.

vorg avatar Aug 04 '22 12:08 vorg