question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use updateConfig

See original GitHub issue

Hi,

Really liking v2.5.0 (especially being able to update options now). The only problem i’m having is how to call updateConfig. I’ve tried a few different things including:

(for the sake of these examples, the chart instance will be called chartInst)

  • Chart.updateConfig(chartInst)
  • chartInst.updateConfig(newOptions)
  • chartInst.updateConfig()
  • updateConfig(chartInst)

But none of these work and there’s nothing in the documentation to explain how to use this new feature. Is anyone able to give me some insight into how it’s used?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
vdhcommented, Feb 23, 2017

@etimberg

This really simple attempt at updating options fails horribly:

chart.options = newOptions;
chart.update();

This would be much less of a headache if the options object (and data, while we’re at it) wasn’t mutated internally…

1reaction
vdhcommented, Feb 26, 2017

@etimberg That’s exactly what I’ve had to do to update the options:

import mergeWith from 'lodash/mergeWith';

const chartJsCustomizer = (existingValue, newValue) => {
  if (Array.isArray(existingValue)) {
    if (
      Array.isArray(newValue) &&
      existingValue.length === newValue.length &&
      existingValue.length > 0 &&
      typeof existingValue[0] === 'object'
    ) {
      // Two arrays of same length with objects, mutate each item instead
      existingValue.forEach((item, index) => {
        mergeWith(item, newValue[index], chartJsCustomizer);
      });
      return existingValue;
    }
    // Replace old array with new value
    return newValue;
  }
  // Default to lodash merge logic
  return undefined;
};

// later…

// Update the options
mergeWith(chart.options, newOptions, chartJsCustomizer);

But the caveats are:

  • It only works if nothing is added/removed to arrays.
  • Can’t remove options that aren’t explicitly null-ed, due to the merge strategy.
  • It will silently fail if an array length doesn’t change due to an even number of additions & removals, because there’s no proper way to track the identity of array items without hardcoding checks for specific options.

This is the kind of rabbit hole that happens when objects are mutated instead of copied 😢

Read more comments on GitHub >

github_iconTop Results From Across the Web

UpdateConfig - AWS Ground Station
Updates the Config used when scheduling contacts. Updating a Config will not update the execution parameters for existing future contacts scheduled with ...
Read more >
updateConfiguration(using:) - Documentation - Apple Developer
Instance Method. updateConfiguration(using:) Updates the cell's configuration using the current state. iOS 14.0+ iPadOS 14.0+ Mac Catalyst 14.0+ tvOS 14.0+ ...
Read more >
Update config command - IBM
Use the update config command to set the Tivoli Storage FlashCopy Manager or Tivoli Storage Manager configuration parameters in a configuration file.
Read more >
Method: projects.updateConfig - Identity Platform - Google Cloud
Encrypt data in use with Confidential VMs. Security Command Center. Platform for defending against threats to your Google Cloud assets.
Read more >
updateConfig — DPBuddy 3.5 Documentation - MyArch
The updateConfig command updates the DataPower configuration based on the value of the “updates” ... Use '.*' for all domains except the default....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found