Open taylorstine opened 9 years ago
toPlainObject
is a utility function for converting the JS SDK's current representation of a Parse Object into a flattened version ideal for Parse+React mutations. This is typically used for the results coming back from a cloud function, but your use case is also valid.
The specific reason we convert arrays of objects into arrays of pointers is that only the latter behaves properly in the Parse API / backend. When you use the SDK directly and save an array of Parse Objects, they will automatically be converted to pointers before they hit our REST API.
In your case, the conversion to a plain object shouldn't be necessary -- Mutations automatically handle receiving SDK-formatted Parse.Objects
. Assuming your code takes in an array of entries
and loops over them, you could just rewrite without any toPlainObject
calls:
function _deleteEntries(entries) {
entries.forEach((entry) => {
ParseReact.Mutation.Destroy(entry)
.dispatch()
.then(() => {
// ...
})
.then((subEntries) => {
this._deleteEntries(subEntries)
})
// ... etc.
What is the purpose of this function? https://github.com/ParsePlatform/ParseReact/blob/master/src/flatten.js#L29-L37 specifically, why does calling
toPlainObject
on an array ofParse.Object
's return a different value than calling it on a single object? For instance, I wanted to do this:where an
Entry
can have a list ofEntries
which point to sub lists etc. But I could not access the second depth ofEntries
because callingtoPlainObject
on an array returns an object without the attributes, instead it returns an object with justclassName
andobjectId
So instead I had to do something like this: