-
Notifications
You must be signed in to change notification settings - Fork 16
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
upgrade ember changeset to v3 #19
upgrade ember changeset to v3 #19
Conversation
Created an issue upstream to investigate what is going on: adopted-ember-addons/ember-changeset-validations#226 |
@@ -1,40 +1,40 @@ | |||
import Controller from '@ember/controller'; | |||
import EmberObject from '@ember/object'; | |||
import { action } from '@ember/object'; | |||
import Changeset from 'ember-changeset'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to verify, can you check the function based approach?
import { Changeset } from 'ember-changeset';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm currently in vacation. Can't check before end of next week. 😟
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in d59192d. Same results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be an easy change over for ya. The class based approach will be deprecated at some point.
I tried lifting the code from this project and adding it directly to my application. After some hacking, I got this to work - not sure if it is the best solution: import BsFormElement from 'ember-bootstrap/components/bs-form/element';
import { tracked } from '@glimmer/tracking';
export default class BsFormElementComponent extends BsFormElement {
@tracked errors;
hasValidator = true;
setupValidations() {
const self = this;
this.model.on('afterValidation', (key) => {
if(key == self.property) {
const errors = self.model.error[key];
self.errors = errors ? errors.validation : null;
}
});
}
} |
@BryanHunt If I get you right, this code is causing errors with I think it includes some bugs. If I didn't missed something it's missing a If tried to change the code accordingly: diff --git a/addon/components/bs-form/element.js b/addon/components/bs-form/element.js
index d5f2611..ec23664 100755
--- a/addon/components/bs-form/element.js
+++ b/addon/components/bs-form/element.js
@@ -9,7 +9,7 @@ export default BsFormElement.extend({
setupValidations() {
let key = `model.error.${this.get('property')}.validation`;
- defineProperty(this, 'errors', computed(`${key}[]`, function() {
+ defineProperty(this, 'errors', computed(`${key}`, function() {
return A(this.get(key));
}));
} Tests are still failing. 😕 I fear Ember Changeset is not correctly notifying on changes to |
Wrote a test for this scenario upstream: adopted-ember-addons/ember-changeset@44c46e1 It's working like expected. I fear my guess was wrong. We need a new theory what's going on. 🤔 |
Also doesn't seem to be related to the inconsitency between ember-changeset and ember-changeset-validations in value type of |
I believe the correct code is: let key = `model.error.${this.get('property')}.validation`;
defineProperty(this, 'errors', computed(`${key}.[]`, function() {
return A(this.get(key));
})); But that doesn't work. The fundamental problem is the computed property is only updated the first time. I posted about this on Discord and @pzuraq mentioned that ember-changeset might not be fully compatible with Octane. I don't really understand the details on the computed property changes. |
Also, to get this to work properly, I had to: get hasValidator() {
return this.model != undefined && this.model.validate != undefined;
} |
@BryanHunt Do you happen to know why it might not be totally compatible with Octane? https://github.com/poteto/ember-changeset/blob/master/addon/index.js#L60 |
From my brief discussion on Discord - I don't fully understand all this:
|
@BryanHunt Sorry I forgot about this when I did the major upgrades :( My initial feeling is that since |
Ember Changeset does not support computed properties anymore for it's state: adopted-ember-addons/ember-changeset#441 😞 One possible fix is observing the original state Refactor @simonihmig What do you think? Is this an acceptable solution for now? @snewcomer Any concerns about using |
@jelhan We are at sort of a crossroads where we are interopt-ing between two different change tracking mechanisms. As a simple start, I would just make get errors() {
return A(get(this, `model.error.${this.property}.validation`));
} I'm also not against a previous solution mentioned by Bryan, but that is a export default class BsFormElementComponent extends BsFormElement {
@tracked errors;
hasValidator = true;
setupValidations() {
const self = this;
this.model.on('afterValidation', (key) => {
if(key == self.property) {
const errors = self.model.error[key];
self.errors = errors ? errors.validation : null;
}
});
}
} |
I agree that the native getter is the way forward. But it would require changes to the validation logic in Ember Bootstrap itself. As the plugin API for validation providers is public API that's not an easy one. Definitely requires more than just changing the computed property here to a native getter. I fear the event based solution might introduce timing issues. I'm tending towards using private API for now until we had the chance to refactor |
I've run into a couple of problems that may or may not be related to my solution. I've opened an issue for the first. I'm still investigating the second. |
@BryanHunt Did you tested this feature branch? |
Unfortunately I am not a
|
7c7249e
to
4991a08
Compare
4991a08
to
f8e7ecc
Compare
Due to the tracked model. This is an incompatibilty issue between tracked properties and computed properties. It's working fine together as long as the computed property observes a tracked property directly. But a computed property can't observe a derived state of a computed property aka native getter. This is also the reason why
Yes. It just moves the issue of native getters not notifying a computed property about the change one level up. To use this approach we would need to drop all native getters in the chain, which requires changes to If no concerns are raised I tend to go with using private API as a hot fix for now. I have rebased this one after #18 has been merged to highlight how small the required change is if we use private API. |
The solution using
|
I don't think this is related to either of our solutions or to ember-bootstrap-changeset-validations. This seems to be this upstream bug: adopted-ember-addons/validated-changeset#22 It should already be fixed in latest version of |
Tests are failing for ember-3.13 due to emberjs/ember.js#18831. I don't expect a fix to be backported to 3.13 as it's not a long-term release. Seems to be a good reason to support only LTS releases and latest minor. Will drop support for Ember 3.13. |
@BryanHunt the error about the circular json structure is fixed in validated-changeset-0.2.3 and has nothing to do with the issue about validations not showing properly. For the matter of this issue: We had a lot of trouble with this and we are now settled with the
// some-component-that-renders-a-bs-form-element.js
// ...
constructor() {
this.theModelForTheElement.validate();
}
//... This won't work as the element is rendered after the constructor and therefore We'd need to set the initial errors if there are any when the element is rendered. However doing so in The current solution for users of ember-changeset-validations is to add a |
@ohcibi Can you confirm that all that complexity is not needed if we observe the private property
I disagree. The correct way forward is refactoring |
Well I haven't tested whether or not the approach to observe
Absolutely agreed. As I said I meant "the right way" more for the project I am working on and not for this plugin. |
I'd be happy to accept a PR on ember-changeset! |
I tried to provide such a fix but it wasn't working as expected. I guess some issues caused by overriding a getter provided by a parent class or so. I thought you are considering it as a won't fix. But to be honest I don't want to invest more time than needed into this one. Will release a stable version of Ember Bootstrap v4 hopefully within the next two months, which includes a refactor to tracked properties. So only an interim solution for a short period of time is needed. |
Just released |
Based on #18, which should be merged before. Need to resolve the failing tests before.