vazco / universe-modules

Use ES6 / ES2015 modules in Meteor with SystemJS
https://atmospherejs.com/universe/modules
MIT License
52 stars 7 forks source link

static class getter method not working #33

Closed rhythnic closed 8 years ago

rhythnic commented 8 years ago

This might be a configuration problem on my part, but i'm using a static getter in a class definition that's not working. Static methods work, just not static getters.

// customer.import.js
const customerDB = new Mongo.Collection('customers');

export default class CustomerBase extends DBModel{
  constructor(doc) {
    super(doc);
  }
  static get db() {
    return customerDB;
  }
....

// file.import.js
import Customer from './customer'
console.log(Customer.db);
// prints 'undefined'

... but if I remove the 'get' from the static definition, then this works.

Customer.db()

Any ideas?

cristo-rabani commented 8 years ago

Do you have lastest version of universe:modules?

Did you tied catch error in promise or in this function ?

Please change content of this function on simple 'return "test"; ' I think the problem is because You have an exception here.

rhythnic commented 8 years ago

I'm using Meteor 1.2.1 and modules 0.6.1 and modules compiler 1.0.2. Also, this is occurring inside of a package.

It seems like an issue with the inheritance of static getters.

// server/main.import.js
import Customer from '../lib/classes/customer'
console.log(Customer.testOne)
 // undefined
console.log(Customer.testTwo)
// test two

// lib/classes/customer.import.js
import CustomerBase from './base/customer'
export default class Customer extends CustomerBase {
  constructor(){}
  static get testTwo() {
    return 'test two';
  }
}

// lib/classes/base/customer.import.js
export default class CustomerBase  {
  constructor(){}
  static get testOne() {
    return 'test one';
  }
}

It works if you forward the getter like this.

// server/main.import.js
import Customer from '../lib/classes/customer'
console.log(Customer.testOne)
 // test one
console.log(Customer.testTwo)
// test two

// lib/classes/customer.import.js
import CustomerBase from './base/customer'
export default class Customer extends CustomerBase {
  constructor(){}
  static get testOne() {
    return super.testOne;
  }
  static get testTwo() {
    return 'test two';
  }
}

// lib/classes/base/customer.import.js
export default class CustomerBase  {
  constructor(){}
  static get testOne() {
    return 'test one';
  }
}
MacRusher commented 8 years ago

Are you sure that this is related to modules and its not some strange corner case babel bug?

Does it work when you execute everything inside one file? (sorry I cannot test this myself right now)

rhythnic commented 8 years ago

I have tested it on the babel playground and it works, but I haven't tested it yet in the app outside of modules. I'll create a test case in a normal .js file in the app and get back to you. On Oct 28, 2015 7:51 AM, "Maciek Stasiełuk" notifications@github.com wrote:

Are you sure that this is related to modules and its not some strange corner case babel bug?

Does it work when you execute everything inside one file? (sorry I cannot test this myself right now)

— Reply to this email directly or view it on GitHub https://github.com/vazco/universe-modules/issues/33#issuecomment-151667939 .

MacRusher commented 8 years ago

You can also try inside both .import.js and plain .js file (with ecmascript package on), this could clear the situation. Thanks!

rhythnic commented 8 years ago

I just confirmed that the error happens outside of the modules package. Thanks for your help.