Skip to content
This repository was archived by the owner on Dec 23, 2018. It is now read-only.
This repository was archived by the owner on Dec 23, 2018. It is now read-only.

Changing data does not invoke onDataChange #63

@nijikokun

Description

@nijikokun

Perhaps I am missing some crucial information regarding the data object, it appears to be immutable, so does that mean I must create a snapshot every time I wish to modify it.

var UserModel = Caplet.createModelClass({
  initialize: function () {
    console.log('Initialized:', this.data)
  },

  onChange: function (data) {
    console.log('Saving Model Data', this.data)
  },

  setTokenData: function (token) {
    // here is where it happens, you have to clone it then set it
    var data = this.toData(this.data)
    data.token = token
    return this.set('data', data)
  }
})

The above will invoke onDataChange properly, however, this example will not:

this.set('data.token', token) 

Meaning now there are two states on the model, direct properties user.token and user.data.token which are no longer synced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions