Skip to content

Commit 9301716

Browse files
Merge pull request cerebral#157 from cerebral/proxyFixes
Proxy fixes
2 parents 24e6021 + 2331714 commit 9301716

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ describe('FUNCTIONS', () => {
451451

452452
expect(tree.get().foo).toBe('bar')
453453
})
454+
test('should be able to set functions', () => {
455+
const tree = new ProxyStateTree({})
456+
const state = tree.get()
457+
458+
tree.startMutationTracking()
459+
state.foo = () => 'bar'
460+
tree.clearMutationTracking()
461+
462+
expect(state.foo()).toBe('bar')
463+
})
454464
test('should pass proxy-state-tree instance and path', () => {
455465
const state = {
456466
foo: (proxyStateTree, path) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class ProxyStateTree {
102102
const tree = this.parentTree || this
103103
const flushId = tree.currentFlushId++
104104

105-
for (let objectChange of tree.objectChanges) {
105+
for (let objectChange of this.objectChanges) {
106106
if (tree.pathDependencies[objectChange]) {
107107
paths.add(objectChange)
108108
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ function createObjectProxy(tree, value, path) {
165165
})
166166
}
167167

168+
if (typeof value === 'function') {
169+
return Reflect.set(target, prop, () => value)
170+
}
171+
168172
return Reflect.set(target, prop, value)
169173
},
170174
deleteProperty(target, prop) {

0 commit comments

Comments
 (0)