Skip to content
This repository was archived by the owner on Apr 22, 2021. It is now read-only.
This repository was archived by the owner on Apr 22, 2021. It is now read-only.

Multiple model change events #62

@TheBox193

Description

@TheBox193

I noticed that when a listener is in place this.listenTo(this.model, 'change', this.doSomething); and an model is loaded that has a related model inside, the model's 'Changed' event will be fired multiple times. Once for the initial state with the full object, and once for when the related model's id is put in place.

For instance if a Post model were loaded with (assuming proper post->user relation):

{
    "post": {
        "id":5,
        "user": {
            "id":10,
            "name": "Joe",
            "username": "joe123"
        },
        "message": "Hello World!"
    }
}

The 'change' event would fire once with the resulting model containing only {"user_id":10} then fired again once when the model's attributes are added. {"id":5, "user_id":10, "message":"Hello World!"}.

Is there a way to prevent the change event from firing until the model is actually loaded?
Currently tasks in an app that listen for model changes currently would need to guess if the model is actually filled / ready.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions