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.

Allow for nested objects as data/keys

See original GitHub issue

Firstly, thanks so much for this lib. It’s really useful for a project I’m currently working on and the code is really easy to follow. Awesome work! 🙌

For my project I’m using nested data objects that I pass to the format method. Right now I have to flatten the object for it to work, for example this:

var data = {
  'user': 'Steve',
  'members': {
    'count': 10
  }
};

becomes:

var data = {
  'user': 'Steve',
  'members.count': 10
};

This works fine but when the data object is huge, with lots of nested data we don’t care about, it becomes a bit of a performance issue.

A work around for this would be to update the interpretSimple function to be:

function interpretSimple (id) {
  return function format (args) {
    var parts = id.split('.');
    if (parts.length > 1) {
      var i = 0;
      var l = parts.length;
      var a = args;
      for (i; i < l; i++) {
        a = a[parts[i]];
        if (!a) return '' + args[id];
      }
      return '' + a;
    }
    return '' + args[id];
  }
}

This would look for nested variables in an object but would fallback to how things currently work, so would be a minor update / backwards compatible.

Is this something that could be consider? If yes I can put together a PR today along with updated unit tests etc.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
minimalmonkeycommented, Oct 6, 2016

Awesome, thanks for the direction. Will take a look at this before making a PR.

0reactions
zdfscommented, Jan 17, 2017

Thank you so much, Andy. This really helps us a lot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dataKey should allow for nested properties... #1329 - GitHub
We have a scenario where our row data is an object with nested properties, like so: { "name": 'bob', "metaData": { "foo": 'x', ......
Read more >
how to use multiple Datakeys in Nested Gridview?? - MSDN
i bound in in databound event of parrent grid. protected void grwEXAMDTL_RowDataBound(object sender, GridViewRowEventArgs e) { GridViewRow row = ...
Read more >
Access nested JSON property in jspdf autotable plugin
Is it possible to assign a dataKey in the columns definition to a nested property within the JSON that is being mapped to...
Read more >
Recharts: nested data using dataKey - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
Exploring Recharts: different ways of accessing data
Passing data in dataKey helps with some level of customization to allow accessing data or nested data directly using object keys.
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