-
-
Notifications
You must be signed in to change notification settings - Fork 113
Fix for passing fragment arrays to fragments #364
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,41 @@ module('unit - `MF.fragmentArray`', function(hooks) { | |
| }); | ||
| }); | ||
|
|
||
| test('fragment arrays can be added to fragments', function(assert) { | ||
| let order = store.createFragment('order', { | ||
| amount: '799.98', | ||
| products: [ | ||
| { | ||
| name: 'Tears of Lys', | ||
| sku: 'poison-bd-32', | ||
| price: '499.99' | ||
| }, | ||
| { | ||
| name: 'The Strangler', | ||
| sku: 'poison-md-24', | ||
| price: '299.99' | ||
| } | ||
| ] | ||
| }); | ||
| let user = store.createRecord('user', { | ||
| info: { | ||
| name: 'Tyrion Lannister', | ||
| notes: ['smart', 'short'] | ||
| }, | ||
| orders: [ | ||
| { | ||
| amount: '799.98', | ||
| products: order.products | ||
| } | ||
| ] | ||
| }); | ||
| assert.equal(user.orders.firstObject.products.firstObject.name, 'Tears of Lys', 'No problems'); | ||
|
|
||
| order.products.firstObject.set('name', 'Wolfsbane'); | ||
| assert.equal(order.products.firstObject.name, 'Wolfsbane', 'Modifies the original fragment array'); | ||
| assert.equal(user.orders.firstObject.products.firstObject.name, 'Tears of Lys', 'It does not modify the passed fragment array'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @richgt @igorT so it appears this approach this means we lose a reference to the fragment array when we pass it in and copy it. See this test where I modify the original array to have the value 'Wolfsbane' but the value of the product within the Digging into this a bit more, the difference between this and the old With the recent refactor we are now always calling To tell you the truth I'm not entirely sure what is the right behavior here but possibly in the spirit of the original code it should just do a simple assignment instead of re-setting up the data? I guess the original code suffered from the problem where the wrong owner is assigned to the fragmentArray? if (serverFragment instanceof StatefulArray) {
serverFragment[name] = data.attributes[name];
} else {
...
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @igorT @richgt I'm just wondering what's the best way to proceed here. Solution 1This PR in its current form.
Solution 2
Thinking about it my preference would be Solution 2, not requiring the |
||
| }); | ||
|
|
||
| test('fragments can be removed from the fragment array', function(assert) { | ||
| run(() => { | ||
| store.push({ | ||
|
|
||
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.
@igorT added an instanceof check instead of using a specific property