Git Product home page Git Product logo

ember-enum's People

Contributors

ember-tomster avatar rmachielse avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ember-enum's Issues

404 in NPM?

when i run ember install ember-enum, an error raised. Did you removed it from npm?

updating the enum value does not flag the model as dirty

I have a model such as:

import DS from 'ember-data';

export default DS.Model.extend({

  currency: DS.attr('enum', {
    options: [
      'EUR',
      'USD'
    ],
    defaultValue: 'EUR'
  })

});

Updating the model's value won't flag it as dirty:

 model.set('currency.value', 'USD');
 console.log(model.get('hasDirtyAttributes')); // false

How to actually set the value?

When the record is loaded from server, model.kind.value is set. When creating a new record this seems broken :(

Here's the thingy.js model:

export default DS.Model.extend({
    name: DS.attr('string'),

    kind: DS.attr('enum', {
        options: ['abc', 'xyz', 'foo', 'bar'],
        defaultValue: 'abc'
    }),
});

When the data comes from the adapter/serializer:

// thingy.get('kind')  => xyz (correct)
// thingy.get('kind.value')  => xyz (correct)
// thingy.get('kind.isXyz')  => true (correct)

But when I'm trying to create a record, the values are broken. Tried the following variations. Neither of them work as expected:

const thingy = this.get('store').createRecord('thingy', {
    kind: 'xyz'
});

// thingy.get('kind')  ==> xyz (correct)
// thingy.get('kind.value')  => null (WRONG)
// thingy.get('kind.isXyz')  => null (WRONG)

and

const thingy = this.get('store').createRecord('thingy');
thingy.set('kind', 'xyz');

// thingy.get('kind')  ==> xyz (correct)
// thingy.get('kind.value')  => null (WRONG)
// thingy.get('kind.isXyz')  => null (WRONG)

and

const thingy = this.get('store').createRecord('thingy');
thingy.set('kind.value', 'xyz');

// causes Assertion Failed: Cannot call set with 'value' on an undefined object. (WRONG)

So what's the correct way to set the value?

`get` is not a function

Hi there,

When I try to create a new model with the following attribute:

  currency: attr('enum', {
    options: [
      'EUR',
      'USD'
    ],
    defaultValue: 'EUR'
  }),

I have a get is not a function in the serialize method:

  serialize(deserialized) {
    if (deserialized) {
      return deserialized.get('value');
    }
  }

The deserialized parameter is a string with EUR as value, not an Ember.Object.

I'm using ember-data 2.9, is it a breaking change? Or there are cases where deserialized may be an object ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.