Skip to content

Commit

Permalink
bug(serialize): Make internal nodes (objects) queryable
Browse files Browse the repository at this point in the history
Also add test cases for this case.
  • Loading branch information
ajtejankar committed Jan 31, 2016
1 parent 1bac982 commit 2bc7a9d
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/serialize.js
Original file line number Diff line number Diff line change
@@ -7,10 +7,10 @@ export default function serialize(obj, paths, currentPath) {
let val = obj[key];
let newPath = `${currentPath}/${key}`;

if (isPrimitive(val)) {
paths = paths || {};
paths[newPath] = val;
} else {
paths = paths || {};
paths[newPath] = val;

if (!isPrimitive(val)) {
paths = serialize(val, paths, newPath);
}
}
3 changes: 3 additions & 0 deletions test/serialize.js
Original file line number Diff line number Diff line change
@@ -17,10 +17,13 @@ describe('serialize', () => {
'/number': 1,
'/boolean': false,
'/string': 'some',
'/array': [1, 2, 3, { random: 'random' }],
'/array/0': 1,
'/array/1': 2,
'/array/2': 3,
'/array/3': { random: 'random' },
'/array/3/random': 'random',
'/object': { some: 'some' },
'/object/some': 'some'
});
});

0 comments on commit 2bc7a9d

Please sign in to comment.