Skip to content

Commit

Permalink
Fixed stack overflow for @computed on RN, fixes #1777
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Dec 3, 2018
1 parent 983ef0b commit 0cdc6df
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/api/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const computedDecorator = createPropDecorator(
const { get, set } = descriptor // initialValue is the descriptor for get / set props
// Optimization: faster on decorator target or instance? Assuming target
// Optimization: find out if declaring on instance isn't just faster. (also makes the property descriptor simpler). But, more memory usage..
// Forcing instance now, fixes hot reloadig issues on React Native:
const options = decoratorArgs[0] || {}
defineComputedProperty(instance, propertyName, { get, set, ...options })
}
Expand Down
12 changes: 6 additions & 6 deletions test/base/babel-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ test("enumerability", () => {
@computed
get b() {
return this.a
} // non-enumerable, on proto
} // non-enumerable, (and, ideally, on proto)
@action
m() {} // non-enumerable, on proto
@action m2 = () => {} // non-enumerable, on self
Expand All @@ -596,8 +596,8 @@ test("enumerability", () => {
expect(props).toEqual(["a", "a2"])

expect("a" in a).toBe(true)
expect(a.hasOwnProperty("a")).toBe(false) // true would better..
expect(a.hasOwnProperty("b")).toBe(false)
expect(a.hasOwnProperty("a")).toBe(false)
expect(a.hasOwnProperty("b")).toBe(false) // true would be more consistent, see below
expect(a.hasOwnProperty("m")).toBe(false)
expect(a.hasOwnProperty("m2")).toBe(true)

Expand All @@ -624,7 +624,7 @@ test("enumerability", () => {
expect("a" in a).toBe(true)
expect(a.hasOwnProperty("a")).toBe(true)
expect(a.hasOwnProperty("a2")).toBe(true)
expect(a.hasOwnProperty("b")).toBe(true) // better, false, but, see: #1398
expect(a.hasOwnProperty("b")).toBe(true) // true would better.. but, #1777
expect(a.hasOwnProperty("m")).toBe(false)
expect(a.hasOwnProperty("m2")).toBe(true)
})
Expand All @@ -636,7 +636,7 @@ test("enumerability - workaround", () => {
@computed
get b() {
return this.a
} // non-enumerable, on proto
} // non-enumerable, (and, ideally, on proto)
@action
m() {} // non-enumerable, on proto
@action m2 = () => {} // non-enumerable, on self
Expand All @@ -663,7 +663,7 @@ test("enumerability - workaround", () => {
expect("a" in a).toBe(true)
expect(a.hasOwnProperty("a")).toBe(true)
expect(a.hasOwnProperty("a2")).toBe(true)
expect(a.hasOwnProperty("b")).toBe(true) // better, false, but, see: #1398
expect(a.hasOwnProperty("b")).toBe(true) // ideally, false, but #1777
expect(a.hasOwnProperty("m")).toBe(false)
expect(a.hasOwnProperty("m2")).toBe(true)
})
Expand Down
6 changes: 3 additions & 3 deletions test/base/typescript-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ test("enumerability", () => {
@computed
get b() {
return this.a
} // non-enumerable, on proto
} // non-enumerable, (and, ideally, on proto)
@action
m() {} // non-enumerable, on proto
@action m2 = () => {} // non-enumerable, on self
Expand All @@ -826,7 +826,7 @@ test("enumerability", () => {

t.equal("a" in a, true)
t.equal(a.hasOwnProperty("a"), true)
t.equal(a.hasOwnProperty("b"), true) // better, false, but, see: #1398
t.equal(a.hasOwnProperty("b"), true) // false would be slightly better, true also ok-ish, and, see #1777
t.equal(a.hasOwnProperty("m"), false)
t.equal(a.hasOwnProperty("m2"), true)

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

t.equal("a" in a, true)
t.equal(a.hasOwnProperty("a"), true)
t.equal(a.hasOwnProperty("b"), true) // better, false, but, see: #1398
t.equal(a.hasOwnProperty("b"), true) // false would be slightly better, true also ok-ish, and, see #1777
t.equal(a.hasOwnProperty("m"), false)
t.equal(a.hasOwnProperty("m2"), true)
})
Expand Down

0 comments on commit 0cdc6df

Please sign in to comment.