Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Method from imported class undefined

I'm trying to integrate a third party API into my meteor.js app. So the idea is, when on /blog route, the app should call external class' method.

router.js:

import blog from '../imports/scripts/blog';
FlowRouter('/blog', {
  name: 'blog',
  action: function(params) {
    blog.init(); // here I get the error "init is not a function" (it's undefined)
  }
});

blog.js:

export default class Blog {
  constructor(){
    ...
  }

  init() {
    console.log('init blog api');
    ...
  }
}

I'm using the latest meteor (1.4.2.3) and the following npm packages in order to enable ES2015:

"babel-cli": "^6.18.0",
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-es2015": "^6.18.0",
"babel-runtime": "^6.18.0",
"meteor-node-stubs": "^0.2.4",
"webpack": "^1.13.3"

Am I missing anything in my setup that I cannot call blog.init()?

like image 565
afkatja Avatar asked Nov 01 '25 03:11

afkatja


1 Answers

So this is answered by Yan Mayatskiy and Gothdo in their comments, thanks for that. In case anyone was looking for the correct answer:

I needed to instantiate the class I imported, like this:

import Blog from 'blog';
const blog = new Blog();
blog.init();
like image 155
afkatja Avatar answered Nov 03 '25 18:11

afkatja