Skip to content

Commit 925fd2e

Browse files
author
Kevin Verdieck
committed
Make it possible to have falsy values. Fixes #15
1 parent 8019c7f commit 925fd2e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/mosaicUtilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export function getLeaves<T>(tree: MosaicNode<T> | null): T[] {
156156
*/
157157
export function getNodeAtPath<T>(tree: MosaicNode<T> | null, path: MosaicPath): MosaicNode<T> | null {
158158
if (path.length > 0) {
159-
return _.get<MosaicNode<T>>(tree, path) || null;
159+
return _.get<MosaicNode<T>>(tree, path, null!);
160160
} else {
161161
return tree;
162162
}

test/utilitiesSpec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const MEDIUM_TREE: MosaicNode<number> = {
4141
},
4242
};
4343

44+
const FALSY_TREE: MosaicNode<number | string> = {
45+
direction: 'row',
46+
first: 0,
47+
second: '',
48+
};
49+
4450
const NINE_LEAVES = _.range(1, 10);
4551
const THOUSAND_AND_ONE_LEAVES = _.range(1, 1002);
4652

@@ -79,6 +85,9 @@ describe('mosaicUtilities', () => {
7985
it('should return null on null root', () => {
8086
expect(getNodeAtPath(null, ['second', 'first', 'second', 'first'])).to.equal(null);
8187
});
88+
it('should work with falsy values', () => {
89+
expect(getNodeAtPath(FALSY_TREE, ['first'])).to.equal(0);
90+
});
8291
});
8392
describe('getAndAssertNodeAtPathExists', () => {
8493
it('should get root', () => {

0 commit comments

Comments
 (0)