Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined error with attributes #65

Open
GCorbel opened this issue May 17, 2017 · 3 comments
Open

Undefined error with attributes #65

GCorbel opened this issue May 17, 2017 · 3 comments

Comments

@GCorbel
Copy link

GCorbel commented May 17, 2017

I created this SO question where I describe the problem I have with decorators and arguments.

With ember-cli-babel 5, I can do this :

import DS from 'ember-data';
import {alias} from 'ember-computed-decorators';

export default DS.Model.extend({
  @alias('customData.email') email
});

It worked. With ember-cli-babel 6 I have this error : and I have this message email is not defined.

Here is what's generated by ember-cli-babel 5 (without babel-plugin-transform-decorators-legacy) :

define('tiny/models/subscription', ['exports', 'ember-data', 'ember-computed-decorators'], function (exports, _emberData, _emberComputedDecorators) {
  function _createDecoratedObject(descriptors) { var target = {}; for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = true; descriptor.configurable = true; if ('value' in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === 'function') { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError('The decorator for method ' + descriptor.key + ' is of the invalid type ' + typeof decorator); } } } if (descriptor.initializer) { descriptor.value = descriptor.initializer.call(target); } Object.defineProperty(target, key, descriptor); } return target; }

  exports['default'] = _emberData['default'].Model.extend(_createDecoratedObject([{
    key: 'mail',
    initializer: function initializer() {
      return _emberData['default'].attr();
    }
  }, {
    key: 'email',
    decorators: [(0, _emberComputedDecorators.alias)('mail')],
    initializer: function initializer() {
      return email;
    }
  }]));
});

Here is what's generated by ember-cli-babel version 6 (with babel-plugin-transform-decorators-legacy) :

define('tiny/models/subscription', ['exports', 'ember-data', 'ember-computed-decorators'], function (exports, _emberData, _emberComputedDecorators) {
  'use strict';

  Object.defineProperty(exports, "__esModule", {
    value: true
  });

  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
    var desc = {};
    Object['ke' + 'ys'](descriptor).forEach(function (key) {
      desc[key] = descriptor[key];
    });
    desc.enumerable = !!desc.enumerable;
    desc.configurable = !!desc.configurable;

    if ('value' in desc || desc.initializer) {
      desc.writable = true;
    }

    desc = decorators.slice().reverse().reduce(function (desc, decorator) {
      return decorator(target, property, desc) || desc;
    }, desc);

    if (context && desc.initializer !== void 0) {
      desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
      desc.initializer = undefined;
    }

    if (desc.initializer === void 0) {
      Object['define' + 'Property'](target, property, desc);
      desc = null;
    }

    return desc;
  }

  var _dec, _desc, _value, _obj, _init;

  exports.default = _emberData.default.Model.extend((_dec = (0, _emberComputedDecorators.alias)('mail'), (_obj = { email: email
  }, (_applyDecoratedDescriptor(_obj, 'email', [_dec], (_init = Object.getOwnPropertyDescriptor(_obj, 'email'), _init = _init ? _init.value : undefined, {
    enumerable: true,
    configurable: true,
    writable: true,
    initializer: function initializer() {
      return _init;
    }
  }), _obj)), _obj)));
});

Is it bug

@zaaack
Copy link

zaaack commented Jun 10, 2017

Hit this problem too, but I'm using with mongoose model.

@GCorbel
Copy link
Author

GCorbel commented Jun 11, 2017

@zaaack You have to do this :

import DS from 'ember-data';
import {alias} from 'ember-computed-decorators';

export default DS.Model.extend({
  @alias('customData.email') email: null
});

Just add : null. This is a bug and this is in investigation as you can see here.

@zaaack
Copy link

zaaack commented Jun 11, 2017

@GCorbel,thanks, I'm using with class and turns out it's my I misunderstood about this plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants