-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[Feat] simplified relationship state #4882
Changes from all commits
62abde1
ecd7bf0
de43562
5ce660f
67ef45a
4d0ff66
ba182ca
5abad65
0cb52d9
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 |
---|---|---|
|
@@ -16,6 +16,18 @@ OrderedSet.prototype = Object.create(EmberOrderedSet.prototype); | |
OrderedSet.prototype.constructor = OrderedSet; | ||
OrderedSet.prototype._super$constructor = EmberOrderedSet; | ||
|
||
OrderedSet.prototype.pushMany = function pushMany(additions) { | ||
for (let i = 0; i < additions.length; i++) { | ||
let value = additions[i]; | ||
|
||
if (value) { | ||
this.add(value); | ||
} | ||
} | ||
|
||
return this.size; | ||
}; | ||
|
||
OrderedSet.prototype.addWithIndex = function(obj, idx) { | ||
let guid = guidFor(obj); | ||
let presenceSet = this.presenceSet; | ||
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. This is unfortunately private API that will change. Ember-data shouldn't be reaching into private state.. hmmm 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. I think the only thing is to add this to ember's, and have ember's lazily create 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. This part is pre-existing, but I agree. I feel we really just need to build an OrderedSet with good perf and tailored to ember-data, given that it exists inside of Ember mostly for ember-data to begin with. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,7 +105,7 @@ export default class RelationshipPayloads { | |
@method | ||
*/ | ||
push(modelName, id, relationshipName, relationshipData) { | ||
this._pendingPayloads.push([modelName, id, relationshipName, relationshipData]); | ||
this._pendingPayloads.push(modelName, id, relationshipName, relationshipData); | ||
} | ||
|
||
/** | ||
|
@@ -150,19 +150,19 @@ export default class RelationshipPayloads { | |
if (this._pendingPayloads.length === 0) { return; } | ||
|
||
let payloadsToBeProcessed = this._pendingPayloads.splice(0, this._pendingPayloads.length); | ||
for (let i=0; i<payloadsToBeProcessed.length; ++i) { | ||
let modelName = payloadsToBeProcessed[i][0]; | ||
let id = payloadsToBeProcessed[i][1]; | ||
let relationshipName = payloadsToBeProcessed[i][2]; | ||
let relationshipData = payloadsToBeProcessed[i][3]; | ||
for (let i = 0; i < payloadsToBeProcessed.length; i += 4) { | ||
let modelName = payloadsToBeProcessed[i]; | ||
let id = payloadsToBeProcessed[i + 1]; | ||
let relationshipName = payloadsToBeProcessed[i + 2]; | ||
let relationshipData = payloadsToBeProcessed[i + 3]; | ||
|
||
// TODO: maybe delay this allocation slightly? | ||
let inverseRelationshipData = { | ||
data: { | ||
id: id, | ||
type: modelName | ||
} | ||
} | ||
}; | ||
|
||
// start flushing this individual payload. The logic is the same whether | ||
// it's for the left hand side of the relationship or the right hand side, | ||
|
@@ -324,7 +324,7 @@ export default class RelationshipPayloads { | |
return; | ||
} | ||
|
||
if (Array.isArray(data)) { | ||
if (data.length) { // dirty-check for "is-array" | ||
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. whats wrong with 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. I'd recommend to stick to 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. 👍 |
||
// TODO: diff rather than removeall addall? | ||
for (let i=0; i<data.length; ++i) { | ||
this._removeFromInverse(id, data[i].id, inverseIdToPayloads); | ||
|
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.
unit test
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.
👍