Skip to content

Commit

Permalink
Fix bug with deriving default key from undefined props.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariusandra committed Mar 16, 2023
1 parent e5b3853 commit 6f05ff6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## 3.1.5 - 2023-03-16
- Fix bug with deriving default key from undefined props.

## 3.1.4 - 2023-01-16

- Support searching by key in `logic.findMounted(123)` and `logic.isMounted('string key')`.
Expand Down
2 changes: 1 addition & 1 deletion src/kea/kea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function kea<L extends Logic = Logic>(
}
wrapper.find = (keyOrProps?: Record<string, any> | KeyType) => {
const builtLogic =
typeof keyOrProps === 'object'
typeof keyOrProps === 'object' || typeof keyOrProps === 'undefined'
? getCachedBuiltLogicByProps<L>(wrapper, keyOrProps)
: getCachedBuiltLogicByKey<L>(wrapper, keyOrProps)
if (builtLogic && getContext().mount.counter[builtLogic.pathString] > 0) {
Expand Down
8 changes: 7 additions & 1 deletion test/jest/mount.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { kea, resetContext, getContext } from '../../src'
import { kea, resetContext, getContext, path, key } from '../../src'

describe('mount', () => {
beforeEach(() => {
Expand Down Expand Up @@ -193,4 +193,10 @@ describe('mount', () => {
expect(logic.isMounted()).toEqual(true)
})
})

test('can mount logic with default key', () => {
const logic = kea([path((key) => ['scenes', 'misc', key]), key(({ id }) => id ?? 'default')])
logic.mount()
expect(logic.isMounted()).toEqual(true)
})
})

0 comments on commit 6f05ff6

Please sign in to comment.