From 0cdc6dffc49ca23a024f59c71a8dc930e349bdf9 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Mon, 3 Dec 2018 18:38:37 +0100 Subject: [PATCH] Fixed stack overflow for @computed on RN, fixes #1777 --- src/api/computed.ts | 1 + test/base/babel-tests.js | 12 ++++++------ test/base/typescript-tests.ts | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/api/computed.ts b/src/api/computed.ts index f32fe255e..52df73b70 100644 --- a/src/api/computed.ts +++ b/src/api/computed.ts @@ -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 }) } diff --git a/test/base/babel-tests.js b/test/base/babel-tests.js index 6999dd276..fef8402f7 100644 --- a/test/base/babel-tests.js +++ b/test/base/babel-tests.js @@ -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 @@ -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) @@ -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) }) @@ -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 @@ -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) }) diff --git a/test/base/typescript-tests.ts b/test/base/typescript-tests.ts index feae1b31b..7e57be58f 100644 --- a/test/base/typescript-tests.ts +++ b/test/base/typescript-tests.ts @@ -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 @@ -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) @@ -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) })