jagi / meteor-astronomy

Model layer for Meteor
https://atmospherejs.com/jagi/astronomy
MIT License
605 stars 66 forks source link

Enum error: values is not a function #625

Closed lobosan closed 7 years ago

lobosan commented 7 years ago

Hi, I was following your video and working with meteor 1.5 but when I added the Enum functionality I got this error:

/home/sgalindo/.meteor/packages/meteor-tool/.1.5.0.utbu0o++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280
                        throw(ex);
                        ^

TypeError: values is not a function
    at Object.Enum.create (packages/jagi:astronomy/lib/modules/fields/Enum.js:43:20)
    at meteorInstall.imports.classes.User.js (imports/classes/User.js:9:21)
    at fileEvaluate (packages/modules-runtime.js:333:9)
    at require (packages/modules-runtime.js:228:16)
    at meteorInstall.server.main.js (server/main.js:1:23)
    at fileEvaluate (packages/modules-runtime.js:333:9)
    at require (packages/modules-runtime.js:228:16)
    at /home/sgalindo/code/meteor/astronomy/.meteor/local/build/programs/server/app/app.js:168:1
    at /home/sgalindo/code/meteor/astronomy/.meteor/local/build/programs/server/boot.js:338:34
    at Array.forEach (native)
Exited with code: 1
Your application is crashing. Waiting for file change.

My code for /imports/classes/User.js is as follows

import { Meteor } from 'meteor/meteor';
import { Astro, Class, Enum } from 'meteor/jagi:astronomy';

Astro.config.defaults = false;

import Users from '../collections/Users';
import Address from './Address';

const Status = Enum.create({
  name: 'Status',
  identifiers: ['ACTIVE', 'INACTIVE']
});

if (Meteor.isClient) {
  window.Status = Status;
}

const User = Class.create({
  name: 'User',
  collection: Users,
  secured: false,
  fields: {
    status: {
      type: Status
    },
    firstName: {
      type: String
    },
    lastName: {
      type: String
    },
    address: {
      type: Address,
      optional: true
    },
    phones: {
      type: [String],
      default() {
        return [];
      }
    },
    birthDate: {
      type: Date,
      immutable: true
    },
    age: {
      type: Number,
      transient: true
    }
  },
  events: {
    afterInit(e) {
      const doc = e.currentTarget;
      let birthDate = doc.birthDate;
      if (birthDate) {
        let diff = Date.now() - birthDate.getTime();
        doc.age = Math.abs((new Date(diff)).getUTCFullYear() - 1970);
      }
    }
  },
  helpers: {
    fullName() {
      return `${this.firstName} ${this.lastName}`;
    }
  }
});

export default User;
lukejagodzinski commented 7 years ago

Ahh sorry indeed, I've introduced a bug in the latest version. It strange that my tests didn't show anything. I have to create additional tests for that feature. I will fix it and deploy a new version of Astronomy.

lukejagodzinski commented 7 years ago

Issue fixed in 2.4.6. Sorry for introducing this bug

lobosan commented 7 years ago

Excellent, now everything is working as expected!