Skip to content

Commit c408b97

Browse files
fix(proxy-state-tree): fix access of undefined and passing in plain object to constructor
1 parent 0533010 commit c408b97

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

packages/node_modules/proxy-state-tree/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import proxify, { IS_PROXY, STATUS } from './proxify'
2+
const isPlainObject = require('is-plain-object')
23

34
export type Options = {
45
devmode: boolean
@@ -21,6 +22,10 @@ class ProxyStateTree {
2122
status: STATUS
2223
proxy: any
2324
constructor(state: object, options: Options = { devmode: true }) {
25+
if (!isPlainObject(state)) {
26+
throw new Error('You have to pass a plain object to the Proxy State Tree')
27+
}
28+
2429
this.state = state
2530
this.options = options
2631
this.pathDependencies = {}

packages/node_modules/proxy-state-tree/src/proxify.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function createArrayProxy(tree, value, path) {
7070
}
7171
}
7272

73+
if (target[prop] === undefined) {
74+
return undefined
75+
}
76+
7377
return (target[prop] = proxify(tree, target[prop], nestedPath))
7478
},
7579
set(target, prop, value) {
@@ -111,6 +115,10 @@ function createObjectProxy(tree, value, path) {
111115
return targetValue(tree, nestedPath)
112116
}
113117

118+
if (targetValue === undefined) {
119+
return undefined
120+
}
121+
114122
return (target[prop] = proxify(tree, targetValue, nestedPath))
115123
},
116124
set(target, prop, value) {

0 commit comments

Comments
 (0)