adopted-ember-addons / adopted-ember-addons/ember-changeset

Cast seems to remove multi level properties like address.country, even if they are included in the array passed to the cast function

Offen
#667 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
JavaScript
Sterne
425
Forks
136
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

## Version

ember-changeset 4.1.1
ember-source 3.28

## Test Case

[Reduced test case here](https://github.com/andrew-paterson/ember-3.28)

## Steps to reproduce

If running the app in the reduced test case above, simply click the button "Test" on the landing page of the above app and look at the console output.

Doing so runs this action, closely based on the docs for `cast`, so you could also just copy and paste this code into a component.

```
export default class TestComponent extends Component {
@action
test() {
let user = { age: 21, address: { zipCode: '10001' } };
let changeset = Changeset(user);
let allowed = ['name', 'address.country'];
console.log(`changeset.set('name', 'Jim Bob');`);
changeset.set('name', 'Jim Bob');
console.log(`changeset.set('address.country', 'United States');`);
changeset.set('address.country', 'United States');
console.log(`changeset.set('unwantedProp', 'foo');`);
changeset.set('unwantedProp', 'foo');
console.log(`changeset.set('address.unwantedProp', 123);`);
changeset.set('address.unwantedProp', 123);
console.log(`changeset.get('name // ${changeset.get('name')}`);
console.log(`changeset.get('address.country // ${changeset.get('address.country')}`);
console.log(`changeset.get('unwantedProp')); // ${changeset.get('unwantedProp')}`);
console.log(`changeset.get('address.unwantedProp // ${changeset.get('address.unwantedProp')}`);
changeset.cast(allowed); // returns changeset
console.log(`>>>> changeset.cast([${allowed}])`);
console.log(`changeset.get('name // ${changeset.get('name')}`);
console.log(`changeset.get('address.country // ${changeset.get('address.country')}`);
console.log(`changeset.get('unwantedProp')); // ${changeset.get('unwantedProp')}`);
console.log(`changeset.get('another.unwantedProp // ${changeset.get('another.unwantedProp')}`);
console.log(changeset.get('another.unwantedProp')); // undefined
}
}
```

## Expected Behavior

Logging `changeset.get('address.country') after `cast` should be `United States`.

```
changeset.set('name', 'Jim Bob');
changeset.set('address.country', 'United States');
changeset.set('unwantedProp', 'foo');
changeset.set('address.unwantedProp', 123);
changeset.get('name // Jim Bob
changeset.get('address.country // United States
changeset.get('unwantedProp')); // foo
changeset.get('address.unwantedProp // 123
>>>> changeset.cast([name,address.country])
changeset.get('name // Jim Bob
changeset.get('address.country // United States
changeset.get('unwantedProp')); // undefined
changeset.get('another.unwantedProp // undefined
```

## Actual Behavior

Logging `changeset.get('address.country') after `cast` is not undefined, where it should be `United States`.
Note that before `cast` it logs as `United States`.
Note also that the same issue does not occur for `name`.

```
changeset.set('name', 'Jim Bob');
changeset.set('address.country', 'United States');
changeset.set('unwantedProp', 'foo');
changeset.set('address.unwantedProp', 123);
changeset.get('name // Jim Bob
changeset.get('address.country // United States
changeset.get('unwantedProp')); // foo
changeset.get('address.unwantedProp // 123
>>>> changeset.cast([name,address.country])
changeset.get('name // Jim Bob
changeset.get('address.country // undefined
changeset.get('unwantedProp')); // undefined
changeset.get('another.unwantedProp // undefined
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.