Skip to content

Mention Object.freeze in documentation #978

Closed
@sherzinger

Description

@sherzinger

I feel it would help many people to mention "Object.freeze" somewhere in the documentation. Maybe some best-practise section when dealing with back-end data.

This becomes very relevant when storing AJAX responses in the state of your component. Usually this data will never change partially, but only as a whole. Not freezing it will heavily impact the performance of the entire component. Freezing the server response (possibly recursively) will prevent this from happening.

Example:

...
data() { 
    foo: 1, 
    serverResponse: null
}
...
vm.foo = 2    <-  fast
vm.serverResponse = {...}  <- large AJAX response
vm.foo = 3 <- very slow
Object.freeze(vm.serverResponse)  <- if data are nested you'll need to do deep/recursive freeze
vm.foo = 4 <- fast

I am not familiar with the inner workings of Vue, but I assume this happens because Vue recursively tracks serverResponse properties.

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