0

I have a javascript object that each attribute is a function:

{
  SetBtcPrice: {
    key: 'SetBtcPrice',
    options: { repeat: [Object], backoff: [Object], attempts: 10 },
    handle: [AsyncFunction: handle]
  },
  SetVenezuelanRate: {
    key: 'SetVenezuelaRate',
    options: { repeat: [Object], backoff: [Object], attempts: 10 },
    handle: [AsyncFunction: handle]
  }
}

I'm exporting it as export default { SetBtcPrice, SetVenezuelanRate }; and I'm importing it in another file as import ExchangeRates from "./exchangeRates"; Then in this file I'm exporting the ExchangeRates and another funtion:

exchangeRates.js:

import SetBtcPrice from "./SetBtcPrice";
import SetVenezuelanRate from "./SetVenezuelaRate";

export default { SetBtcPrice, SetVenezuelanRate };

jobs/index.js:

export { default as UserRegistrationMail } from "./UserRegistrationMail";
import ExchangeRates from "./exchangeRates";

export { ExchangeRates };

In another file I'm importing import * as jobs from "../jobs";, this gives me:

{
  UserRegistrationMail: [Getter],
  ExchangeRates: {
    SetBtcPrice: {
      key: 'SetBtcPrice',
      options: [Object],
      handle: [AsyncFunction: handle]
    },
    SetVenezuelanRate: {
      key: 'SetVenezuelaRate',
      options: [Object],
      handle: [AsyncFunction: handle]
    }
  }
}

How can I deconstruct the ExchangeRates object, so when importing * as jobs it gives me this:

{
  UserRegistrationMail: [Getter],
  SetBtcPrice: {
    key: 'SetBtcPrice',
    options: [Object],
    handle: [AsyncFunction: handle]
  },
  SetVenezuelanRate: {
    key: 'SetVenezuelaRate',
    options: [Object],
    handle: [AsyncFunction: handle]
  }
}
Otavio Bonder
  • 1,789
  • 4
  • 17
  • 35
  • use `export default` combining the objects by spread – NiRUS Nov 28 '19 at 04:02
  • Exporting `export default {...ExchangeRate}` gives me: ``` { UserRegistrationMail: [Getter], default: { SetBtcPrice: { key: 'SetBtcPrice', options: [Object], handle: [AsyncFunction: handle] }, SetVenezuelanRate: { key: 'SetVenezuelaRate', options: [Object], handle: [AsyncFunction: handle] } } } ``` – Otavio Bonder Nov 28 '19 at 04:05
  • Possible duplicate of [\`export const\` vs. \`export default\` in ES6](https://stackoverflow.com/questions/33611812/export-const-vs-export-default-in-es6) – NiRUS Nov 28 '19 at 04:05

2 Answers2

0
export const { SetBtcPrice, SetVenezuelanRate } = ExchangeRates
SeongMin Park
  • 75
  • 1
  • 7
  • This gives me `SyntaxError: Error transforming /Users/otaviobonder/WebstormProjects/newTE/back/src/jobs/index.js: Unexpected token, expected "," (4:13)` – Otavio Bonder Nov 28 '19 at 04:03
0

export { SetBtcPrice, SetVenezuelanRate } from './exchangeRates'

Your default export is an object with SetBtcPrice and SetVenezualanRate as properties. You can destructure those properties in an export statement.

Importing them will be similar:

import { SetBtcPrice, SetVenezuelanRate } from './some/path'

Mike
  • 3
  • 3