In an Ember `.findRecord` promise, object from parent scope must be cloned?


#1

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 the then 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?