Skip to content
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

Fixed snapshot behavior with nested keys #27

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SergeAstapov
Copy link
Contributor

@snewcomer I would need some help/advice how to update restore() method.

In v2 branch of ember-changeset, _changes object was stored as a map/hash with keys in format foo or foo.bar.baz.

validated-changeset stores _changes in format like

{
  foo: {
    bar: {
      baz: 'abc'
    }
  }
}

Because of that changes I'm not sure what would you consider the most efficient way of restoring Changeset from snapshot.

The new test #restore restores a snapshot of the changeset with nested values has been created and it currently fails as no changes to restore() have been made.

@snewcomer
Copy link
Collaborator

@SergeAstapov Quick comment - one of the main motivations in the original rewrite was to store the keys in a nested format internally so as to easily iterate over the object. (I can/should explain more though)

adopted-ember-addons/ember-changeset#379

@SergeAstapov
Copy link
Contributor Author

I see, thanks explanation @snewcomer! I'll try to work on this PR and rewrite implementation so that snapshot produces nested format and restore uses it.

@bartocc
Copy link

bartocc commented Jul 27, 2021

I found this PR and issue #25 while trying to migrate my codebase from ember-changeset-validations 2.x to 3.x.

I get the You attempted to update _changesonchangeset:[object Object], but it had already been used previously in the same computation error.

This happens because if first check {{this.changeset.isDirty}} in a template and later do this.changeset.restore(aSnapshot). My snapshot does not have nested keys though…

Should I consider that restore is broken at the moment in validated-changeset ?

@snewcomer
Copy link
Collaborator

@bartocc Here is a chain of PRs I implemented to solve the case where someone calls .validate() on render (we read ERRORS then write them all in one computation...that is a problem). It sounds like this is the same case. We would need to develop a CHANGES_CACHE as well; however, I found it a bit difficult. One option is to change around your flow so that restore doesn't get called in the same render step (likely when rendering a page). Mind sharing the snippet on where you are calling restore?

adopted-ember-addons/ember-changeset#604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants