@MicFin wrote:
I am sending an plain old javascript object up with through an action to my route file.
In the route file, I am then fetching a record to update it. The
.findRecord()
method returns a resolved promise. However, when inside the.then
my variable declared in the parent scope outside of thethen
is an empty object.routes/task.js
export default Route.extend({ model (params) { const id = params.task_id return this.get('store').findRecord('task', id) }, actions: { saveNotes (updatedTask) { // updatedTask is the expected object {name: "New Name} console.log(`updatedTask outside is:`, updatedTask); this.get('store').findRecord('task', taskID).then(task => { // updatedTask is an empty object {} console.log(`updatedTask inside is:`, updatedTask); task.setProperties(updatedTask) task.save() }) } } });
However, if I clone the object, then the value is correct.
routes/task.js
export default Route.extend({ model (params) { const id = params.task_id return this.get('store').findRecord('task', id) }, actions: { saveNotes (updatedTask) { // updatedTask is the expected object {name: "New Name} console.log(`updatedTask outside is:`, updatedTask); let clone = Object.assign({}, updatedTask) this.get('store').findRecord('task', taskID).then(task => { // clone is the expected object {name: "New Name} console.log(`updatedTask inside is:`, clone); task.setProperties(updatedTask) task.save() }) } } });
Is this expected behavior?
Posts: 1
Participants: 1