ember-changeset: 'getting' a Moment instance on a changeset returns a relay instead of that instance
When having a Moment instance on a changeset, eg.: set(changeset, 'startDate', moment()), and if you then later do get(changeset, 'startDate') it will - instead of returning the Moment instance on the changeset - return a relay with ‘startDate’ as key.
I’m unsure if this is a 100% a bug, as the Moment instance is an object so ember-changeset thinks it has to create a relay, but it would be nice if there were a way to deal with this (eg. defining keys for which no relay should be created, as I’m not going to directly get or modify the internals of the Moment instance).
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 35 (9 by maintainers)
Just to notify everyone,
2.0.0-beta.0has been published for ember-changeset and ember-changeset-validations. Give it a shot! @sevab i think it might fix your issue but don’t quote me on it 😃Got a similar problem, setting a
moment()date on a changeset and then getting it back does not return theMomentobject. setup:After tracking all the callbacks the pivot point I found was in
ember-changeset/addon/index.jsin thegetmethod (line 150).My temporary hack to make it work is to trick the
getmethod into thinking that aMomentobject is abelongsTorelationship (better to have a specific or generalized implementation for this):hopefully this saves somebody the time!
Just ran across this issue, identical problem to what was described by most (changeset + moment + ember-power-calendar) Version 2.0.0 everything works. Thanks @snewcomer! You rawk.
@snewcomer all seems to works with 2.0, thanks!
Though In handlebars had to switch
selected=(hash start=changeset.startDate.content end=changeset.endDate.content)toselected=(hash start=changeset.startDate end=changeset.endDate).Which is a changed behaviour, but more convenient.
I’m still having this issue (or possibly a similar-and-related issue, since mine is happening in the JS for a component and not in a template).
I put together a new app with enough code to reproduce the problem: https://github.com/pgengler/ember-changeset-issue/tree/problems-with-moment
To reproduce
problems-with-momentbranch of that repoyarn installember sGoing to close for now! Lmk if anybody has any questions!
It depends:
class Dog extends EmberObject{}: Will return a relay causeDogextendsEmberObjectand thereforetypeof(new Dog()) === 'instance'istrue.function Dog() {}: Will return instance ofDogcauseObject.getPrototypeOf(val) === Object.prototypeisfalse(and it’s not an instance ofEmberObject).function Dog() {}; Dog.prototype = Object.prototype: Will return a relay cause Object.getPrototypeOf(val) === Object.prototypeistrue` (but I hope nobody is doing something like that).It depends what you consider “the correct type”. I’m arguing that type
"object"of ember’stypeOffunction is to broad for our use case:@snewcomer Your test is fine. While trying to debug I noticed that the bug only occurs if
changesettemplate helper is used. Here is another ember-twiddle demonstrating that it’s working fine if changeset is constructed in code: https://ember-twiddle.com/eeb4e12e66b114c12e7204b218d359a2?openFiles=templates.application.hbs%2CThis is the ember twiddle showing that it’s not working if template helper is used: https://ember-twiddle.com/f38bf913c6c44079ba0c84c148cc9f05?openFiles=templates.application.hbs%2C
Debugged further and noticed that the bug is only occuring if ember getter is used and the value is proxied to content:
Here is an ember-twiddle: https://ember-twiddle.com/a5ea906707f67f978454d0164b1da8ed?openFiles=controllers.application.js%2C
This is not covered by your test since you are only testing getter after setting the value.
Agreed. I’ll find time this week to put up a fix if possible. After that is fixed, let’s release 1.5 proper!
I don’t think this is fixed. Here is a reproduction for
v1.5.0-beta.0: https://ember-twiddle.com/f38bf913c6c44079ba0c84c148cc9f05?openFiles=templates.application.hbs%2C It’s the same if you downgrade ember-changeset to1.4.2-beta.0.If accessing the moment object throw changeset (e.g. using
moment-formathelper as in twiddle) this is blowing up due to.get()assertion:Please note that this assertion is triggered by moment.js code.
The regression has been added in
1.4.0. It’s working fine for1.3.0.