Skip to main content
added 111 characters in body
Source Link
ytiq
  • 4.7k
  • 1
  • 21
  • 44

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

UPDATE

This deep assignment doesn't work, one minute, I'll update to the option with additional variable

UPDATE2 this deep properties are sad( Either just JSON.parse(JSON.stringify)) or set it somewhere else

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

UPDATE

This deep assignment doesn't work, one minute, I'll update to the option with additional variable

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

UPDATE

This deep assignment doesn't work, one minute, I'll update to the option with additional variable

UPDATE2 this deep properties are sad( Either just JSON.parse(JSON.stringify)) or set it somewhere else

added 115 characters in body
Source Link
ytiq
  • 4.7k
  • 1
  • 21
  • 44

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

UPDATE

This deep assignment doesn't work, one minute, I'll update to the option with additional variable

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)

UPDATE

This deep assignment doesn't work, one minute, I'll update to the option with additional variable

Source Link
ytiq
  • 4.7k
  • 1
  • 21
  • 44

The thing is, that shallow copy only changes first level, but deeper levels are still wrapped into readonly proxy, so I recommend doing like this

 getResults(response) {
    const {data, error} = response;

    if (data) {
      this.results = data.map(item => Object.assign({}, item, {
        contentNodes: {
          source: {
            url: 'string'
          }
        }
      }));

      console.log ('cms', this.results);
    } else if (error) {
      // handle error
    }
  }

so you create a separate object and do not modify returned from the Apex.

Not sure about this deep assignment, you might want to do it via separate variable, but Object.assign will do it's job const tmp= Object.assign({}, item)