kosko icon indicating copy to clipboard operation
kosko copied to clipboard

Feature request: ability to export an object from a component

Open moltar opened this issue 5 years ago • 2 comments

Instead of:

export default [ componentName ]

Would be great to be able to do:

export default { componentName }

The use case is that the component can then be much easier consumed from another component by name.

E.g.:

// component-two.ts

import { componentOneService } from './component-one'

// now can do something with component's data
componentOneService.metadata.name

What do you think?

Can just maybe call Object.values() on the component default export, if it's not array.

moltar avatar Mar 30 '19 12:03 moltar

Instead of exporting all variables in default, you can use named exports.

// component-one.js
export const componentOneService = new Service();

// component-two.js
import { componentOneService } from './component-one';

tommy351 avatar Apr 01 '19 07:04 tommy351

Right, of course. But would kosko then pick them up? Or do I need to still have the default export with an array?

moltar avatar Apr 01 '19 07:04 moltar