adopted-ember-addons / ember-changeset

Ember.js flavored changesets, inspired by Ecto
http://bit.ly/ember-changeset-demo
MIT License
431 stars 141 forks source link

Changeset ignore updates after change and delete the same changes #581

Closed usamahamed closed 3 years ago

usamahamed commented 3 years ago

Version

v3.9.2

Test Case

If you change something in the changeset model, the isDirty flag is set to true and if you remove it again it will set to false and if you try to add new changes it will be ignored

Steps to reproduce

I have a model and this model has a label and type is string

1- Add some letter beside the label and then ember will trigger the isDirty flag to indicate that model has changes 2- Remove the the letter i added beside the label, the isDirty flag set to be false again 3- Try to enter any new changes which called set model, it ignores the changes

The changes ignore inside the _run method in the backburner.js

Expected Behavior

if i add and delete and add, it should trigger the changes and update the model with the new changes

Actual Behavior

it doesn't update the model with set after add then delete then add again

betocantu93 commented 3 years ago

I'm facing this issue too:

ember-changeset: v3.13.1 changeset-validations: v3.14.2

ember-source: v3.16.10

Noticed this doesn't happend in another ember app with ember v3.20.6

An easy way to repro

let model = new Changeset({ age: '10'});
model.set('age', '80');
model.set('age', '10') //starting value
model.set('age', '90'); //ignored from now on
snewcomer commented 3 years ago

Thank you! I'll see if I can fix tomorrow

betocantu93 commented 3 years ago

Let me know if I can help you with anything

snewcomer commented 3 years ago

@betocantu93 Here is a test I wrote up. It seems everything is working. Did I miss anything?

  it('#set works', () => {
    const expectedChanges = [{ key: 'age', value: '90' }];
    let dummyChangeset = Changeset({ age: '10' });
    dummyChangeset.set('age', '80');
    dummyChangeset.set('age', '10');
    dummyChangeset.set('age', '90');

    const changes = dummyChangeset.changes;

    expect(dummyModel.age).toBeUndefined();
    expect(dummyChangeset.get('age')).toEqual('90');

    expect(changes).toEqual(expectedChanges);
    expect(dummyChangeset.isDirty).toBe(true);
    expect(dummyChangeset.change).toEqual({ age: '90' });
  });
betocantu93 commented 3 years ago

Hey, it should be showing the error 🤔 here's a repro https://github.com/betocantu93/changeset-bug, with the exact same deps I have on this app

snewcomer commented 3 years ago

@betocantu93 Looks like v3.13.1 is working with this test! I just merged in a PR with this test added. Perhaps you have to update versions?

betocantu93 commented 3 years ago

Yes, maybe I need to update versions... was trying to avoid it to be honest, but this is the way! thanks!

betocantu93 commented 3 years ago

I just want to comment for anyone else landing here: this bug exists from ember-source 3.16.x to 3.19.x, from 3.20+ works

It's not related to changeset but to ember itself.