rmachielse / ember-enum Goto Github PK
View Code? Open in Web Editor NEWEmber Enum
Home Page: https://rmachielse.github.io/ember-enum/
License: MIT License
Ember Enum
Home Page: https://rmachielse.github.io/ember-enum/
License: MIT License
when i run ember install ember-enum
, an error raised. Did you removed it from npm?
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
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?
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 ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.