Skip to content

Commit 8351262

Browse files
committed
Fixed stack overflow for @computed on RN, fixes #1777
1 parent 16f8586 commit 8351262

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

src/api/computed.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export const computedDecorator = createPropDecorator(
2828
const { get, set } = descriptor // initialValue is the descriptor for get / set props
2929
// Optimization: faster on decorator target or instance? Assuming target
3030
// Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
31+
// Forcing instance now, fixes hot reloadig issues on React Native:
3132
const options = decoratorArgs[0] || {}
32-
asObservableObject(instance).addComputedProp(decoratorTarget, propertyName, {
33+
asObservableObject(instance).addComputedProp(instance, propertyName, {
3334
get,
3435
set,
3536
context: instance,

test/base/babel-tests.js

+12-16
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ test("enumerability", () => {
574574
@computed
575575
get b() {
576576
return this.a
577-
} // non-enumerable, on proto
577+
} // non-enumerable, (and, ideally, on proto)
578578
@action
579579
m() {} // non-enumerable, on proto
580580
@action m2 = () => {} // non-enumerable, on self
@@ -587,17 +587,15 @@ test("enumerability", () => {
587587
let props = []
588588
for (var key in a) props.push(key)
589589

590-
expect(ownProps).toEqual(
591-
[
592-
// should have a, not supported yet in babel...
593-
]
594-
)
590+
expect(ownProps).toEqual([
591+
// should have a, not supported yet in babel...
592+
])
595593

596594
expect(props).toEqual(["a", "a2"])
597595

598596
expect("a" in a).toBe(true)
599-
expect(a.hasOwnProperty("a")).toBe(false) // true would better..
600-
expect(a.hasOwnProperty("b")).toBe(false)
597+
expect(a.hasOwnProperty("a")).toBe(false)
598+
expect(a.hasOwnProperty("b")).toBe(false) // true would be more consistent, see below
601599
expect(a.hasOwnProperty("m")).toBe(false)
602600
expect(a.hasOwnProperty("m2")).toBe(true)
603601

@@ -624,7 +622,7 @@ test("enumerability", () => {
624622
expect("a" in a).toBe(true)
625623
expect(a.hasOwnProperty("a")).toBe(true)
626624
expect(a.hasOwnProperty("a2")).toBe(true)
627-
expect(a.hasOwnProperty("b")).toBe(false) // true would also be ok-ish. see: #1398
625+
expect(a.hasOwnProperty("b")).toBe(true) // true would better.. but, #1777
628626
expect(a.hasOwnProperty("m")).toBe(false)
629627
expect(a.hasOwnProperty("m2")).toBe(true)
630628
})
@@ -636,7 +634,7 @@ test("enumerability - workaround", () => {
636634
@computed
637635
get b() {
638636
return this.a
639-
} // non-enumerable, on proto
637+
} // non-enumerable, (and, ideally, on proto)
640638
@action
641639
m() {} // non-enumerable, on proto
642640
@action m2 = () => {} // non-enumerable, on self
@@ -663,7 +661,7 @@ test("enumerability - workaround", () => {
663661
expect("a" in a).toBe(true)
664662
expect(a.hasOwnProperty("a")).toBe(true)
665663
expect(a.hasOwnProperty("a2")).toBe(true)
666-
expect(a.hasOwnProperty("b")).toBe(false) // true would also be ok-ish. see: #1398
664+
expect(a.hasOwnProperty("b")).toBe(true) // ideally, false, but #1777
667665
expect(a.hasOwnProperty("m")).toBe(false)
668666
expect(a.hasOwnProperty("m2")).toBe(true)
669667
})
@@ -701,11 +699,9 @@ test("verify object assign (babel)", () => {
701699
}
702700

703701
const todo = new Todo()
704-
expect(Object.assign({}, todo)).toEqual(
705-
{
706-
// Should be: title: "test"!
707-
}
708-
)
702+
expect(Object.assign({}, todo)).toEqual({
703+
// Should be: title: "test"!
704+
})
709705

710706
todo.title // lazy initialization :'(
711707

test/base/typescript-tests.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ test("enumerability", () => {
802802
@computed
803803
get b() {
804804
return this.a
805-
} // non-enumerable, on proto
805+
} // non-enumerable, (and, ideally, on proto)
806806
@action
807807
m() {} // non-enumerable, on proto
808808
@action m2 = () => {} // non-enumerable, on self
@@ -826,7 +826,7 @@ test("enumerability", () => {
826826

827827
t.equal("a" in a, true)
828828
t.equal(a.hasOwnProperty("a"), true)
829-
t.equal(a.hasOwnProperty("b"), false) // ok also ok-ish
829+
t.equal(a.hasOwnProperty("b"), true) // false would be slightly better, true also ok-ish, and, see #1777
830830
t.equal(a.hasOwnProperty("m"), false)
831831
t.equal(a.hasOwnProperty("m2"), true)
832832

@@ -849,7 +849,7 @@ test("enumerability", () => {
849849

850850
t.equal("a" in a, true)
851851
t.equal(a.hasOwnProperty("a"), true)
852-
t.equal(a.hasOwnProperty("b"), false) // true would also be ok-ish, see: #1398
852+
t.equal(a.hasOwnProperty("b"), true) // false would be slightly better, true also ok-ish, and, see #1777
853853
t.equal(a.hasOwnProperty("m"), false)
854854
t.equal(a.hasOwnProperty("m2"), true)
855855
})

0 commit comments

Comments
 (0)