-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
'getting' a Moment instance on a changeset returns a relay instead of that instance #229
Comments
Thanks for reporting! This is similar to a1d22b7, I'd consider this a bug. Will include this in the upcoming bugfix release (1.4.2). |
As mentioned on Slack, for now you could try |
@PieterJanVdb The latest release v1.4.2-beta.0 fixes this. You can write If you have the time, please try it out (with caution :D). It should still work with (Official announcement post is over on Ember Way). |
I don't think this is fixed. Here is a reproduction for If accessing the moment object throw changeset (e.g. using
Please note that this assertion is triggered by moment.js code. The regression has been added in |
This issue needs re-opening, it seems it has made it's way into the latest release! |
Agreed. I'll find time this week to put up a fix if possible. After that is fixed, let's release 1.5 proper! |
@PieterJanVdb @drummy2 @jelhan 👋 Could somebody look at this test I added in #309 and lmk how it diverges from this issue? I am asserting that "getting" |
@snewcomer Your test is fine. While trying to debug I noticed that the bug only occurs if This 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. |
@jelhan I'm a little stumped at the moment. We have existing tests that say using Ember.get will not give you the actual content and that if using Ember.get, you should get via The issue is that Not sure of a solution yet... |
As far as I got it, it's an issue by design. If the original value is an object, a relay is returned: https://github.com/poteto/ember-changeset/blob/v1.5.0-beta.2/addon/index.js#L769-L774 The value is considered an object if ember's Is there a good reason for returning a relay for an object which isn't an instance of EmberObject nor a POJO? This would fix the issue for all objects representing a value but on the other hand still allow to work with nested keys on EmberObject's and POJO's. An implementation would look like this:
|
@jelhan Hm that may work. So my only question is what if val is e.g. |
It depends:
It depends what you consider "the correct type". I'm arguing that type
|
Yeah my concern is if the What we ultimately want is something like this line. If it is a relay, return the |
I'm starting to wonder if we need to rethink or rejigger how |
Alrighty the template helper has been fixed. Should not return a Relay instance anymore! |
Going to close for now! Lmk if anybody has any questions! |
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
|
What scenarios should be considered fixed? Using a moment instance stored in a changeset with moment helpers still throws using 1.5.0. This was the scenario in my first ember twiddle. You tried to update the version of ember-changeset but it still throws. Please note that this is a regression added 1.4.x. The twiddle is working fine with 1.3.0. |
Let me give some more insight what these ember twiddle does:
The only work-a-round is to access the underlying object through Maybe I didn't got the point, but what benefits do we have from using a relay for complex objects like moment at all? Or to put it another way around: Why do we use a relay for a moment instance but not for
The parens are causing |
@jelhan I see. Yep the parens are needed 👍 thx. I was mistaken. Accessing the Truthfully there are use cases for which the You are 100% right that we could scope this to only POJOs and EmberObjects. I think at a minimum, putting up a PR for now would be helpful. I just don't know what all the uses are out there in the wild for ember-changeset. Me personally - I just use them for EmberObjects. |
Not sure if this is related to this issue: I run a custom validation (via I then pass the changeset value to setMomentDate(momentRange) {
let { start, end } = momentRange;
this.get('changeset').setProperties({
startDate: start,
endDate: end
});
} As I change the dates and validation passes, However, when validation fails, changeset sets moment instance directly on Not sure if this is expected behaviour of This is on latest |
Just to notify everyone, |
@snewcomer all seems to works with 2.0, thanks! Though In handlebars had to switch Which is a changed behaviour, but more convenient. |
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. |
Got a similar problem, setting a
After tracking all the callbacks the pivot point I found was in My temporary hack to make it work is to trick the now = moment()
now.constructor.prototype.isLoading = true
now.constructor.prototype.isLoaded = true
now.constructor.prototype.isNew = true
now.constructor.prototype.hasDirtyAttributes = true hopefully this saves somebody the time! |
@bterkuile |
Thank you @snewcomer, the solution looks nice. I guess the strategy is that the
My understanding of what exactly is happening is low, so don't know where the cause of this is. Maybe the Ember |
@bterkuile Can you see a failing test that captures your case? I'm having trouble viewing your use case. Honestly I have not been a fan of this block. I was leary about it when it first went into master but could not think of an alternative solution. I'm throwing around the idea of a |
@snewcomer I'll give it a shot, it will take some digging in finding out how these moment attributes are created |
To create the failing test: Step 1.Check keys on let netKeys = Object.keys(result).filter(k => !this.safeGet(result, k)); Step 2Add a dynamic attribute having a non truthy value: test('#set adds a change if value is an object with existing value', async function(assert) {
class Moment {
constructor(date) {
this.date = date;
}
}
let d = new Date();
dummyModel.set('startDate', new Moment(d));
dummyModel.set('name', 'Bobby');
let c = Changeset(dummyModel);
d = new Date();
let momentInstance = new Moment(d);
momentInstance._isUTC = false;
c.set('startDate', momentInstance);
let expectedChanges = [{ key: 'startDate', value: momentInstance }];
let changes = get(c, 'changes');
assert.deepEqual(changes, expectedChanges, 'should add change');
let newValue = c.get('startDate');
assert.deepEqual(newValue, momentInstance, 'correct getter');
assert.ok(newValue instanceof Moment, 'correct instance');
assert.equal(newValue.date, d, 'correct date on moment object');
newValue = get(c, 'startDate');
assert.deepEqual(newValue, momentInstance, 'correct getter');
assert.ok(newValue instanceof Moment, 'correct instance');
assert.equal(newValue.date, d, 'correct date on moment object');
});
|
Got an idea working that allows objects to behave as 'leaf' objects. Don't know if it fits and some other specs are failing with these changes.
|
@bterkuile Thank you! I see the general problem and it is a tough problem. We can handle Effectively, we need to re-create that object when you Will try to think through a solution. Reopening and thank you for sticking through with this! |
@snewcomer thank you for thinking along with this, I guess it's a complex yet interesting problem connected with the changeset way of handling data. I guess especially starting with a |
Ideally we flip the solution. Instead of keeping track of the We are right in the crosshairs of structured cloning, but not something we can do at this time (ever?) and seems like abusing an API. My feeling is that we have to live with shallow clones if we have to merge sibling keys to/or from I'll explore this today... |
When having a Moment instance on a changeset, eg.:
set(changeset, 'startDate', moment())
, and if you then later doget(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).
@nucleartide
The text was updated successfully, but these errors were encountered: