kwhitley / treeize

Converts row data (in JSON/associative array format) to tree structure based on column naming conventions.
MIT License
189 stars 24 forks source link

[POSSIBLE OPTION] handle graceful pruning when low level node not found #12

Closed kwhitley closed 10 years ago

kwhitley commented 10 years ago

e.g.

{ "node:attr1": "foo", "node:attr2": "bar" }

Shouldnt add deep attributes to unknown object (currently dumps to root because trail not added).

NOTES

kwhitley commented 10 years ago
var tree = new Treeize();

tree.setOptions({ log: true }).grow([
  { 'foo:name': 'bar', 'foo:age': 1 },
  { 'foo:name': 'baz', 'foo:age': 3 },
]);

Produces error:

SIGNATURE> { nodes: 
   [ { path: 'foo',
       attributes: 
        [ { name: 'name', key: 'foo:name' },
          { name: 'age', key: 'foo:age' } ],
       blueprint: 
        [ { name: 'name', key: 'foo:name' },
          { name: 'age', key: 'foo:age' } ],
       isCollection: false,
       name: 'foo',
       depth: 1,
       parent: '' } ],
  type: 'object',
  isFixed: false }
PROCESSING NODE> { path: 'foo',
  attributes: 
   [ { name: 'name', key: 'foo:name' },
     { name: 'age', key: 'foo:age' } ],
  blueprint: 
   [ { name: 'name', key: 'foo:name' },
     { name: 'age', key: 'foo:age' } ],
  isCollection: false,
  name: 'foo',
  depth: 1,
  parent: '' }
creating attribute "name" within blueprint bar
creating attribute "age" within blueprint 1
creating attribute "name" within extended blueprint bar
creating attribute "age" within extended blueprint 1
EXTENDED BLUEPRINT> { name: 'bar', age: 1 }
BLUEPRINT> { name: 'bar', age: 1 }
path MISSING for location ""
..attempting path location for ""
..attempting path location for ""
..attempting path location for ""
..attempting path location for ""
..attempting path location for ""
..attempting path location for ""
path FOUND for location for "" after removing 6 segments
creating or trailing path segment {object} ""

/Users/kevinwhitley/dev/kwhitley/treeize/lib/treeize.js:336
                  trail = trail[segment] = trail[segment] || {};
                                                ^
TypeError: Cannot read property '' of undefined
    at Treeize.<anonymous> (/Users/kevinwhitley/dev/kwhitley/treeize/lib/treeize.js:336:49)
    at /Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:4446:21
    at Function.forEach (/Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:2590:15)
    at Treeize.<anonymous> (/Users/kevinwhitley/dev/kwhitley/treeize/lib/treeize.js:326:17)
    at /Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:4446:21
    at Function.forEach (/Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:2590:15)
    at Treeize.<anonymous> (/Users/kevinwhitley/dev/kwhitley/treeize/lib/treeize.js:235:7)
    at /Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:4446:21
    at Function.forEach (/Users/kevinwhitley/dev/kwhitley/treeize/node_modules/lodash/dist/lodash.js:2590:15)
    at Treeize.grow (/Users/kevinwhitley/dev/kwhitley/treeize/lib/treeize.js:202:5)