From b73f24fc0d5b36d0089052a9df9c6c2f8433f5b0 Mon Sep 17 00:00:00 2001 From: Michel Weststrate Date: Wed, 31 Aug 2016 08:48:52 +0200 Subject: [PATCH] make sure computed() created properties use the correct name --- src/types/observableobject.ts | 2 ++ test/extras.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/types/observableobject.ts b/src/types/observableobject.ts index e7451fe3b..171ff6756 100644 --- a/src/types/observableobject.ts +++ b/src/types/observableobject.ts @@ -82,9 +82,11 @@ export function defineObservableProperty(adm: ObservableObjectAdministration, pr if (newValue instanceof ObservableValue) { observable = newValue; + newValue.name = name; isComputed = false; } else if (newValue instanceof ComputedValue) { observable = newValue; + newValue.name = name; if (!newValue.scope) newValue.scope = adm.target; } else if (typeof newValue === "function" && newValue.length === 0 && !isAction(newValue)) { diff --git a/test/extras.js b/test/extras.js index 7166d901b..591fa7e9d 100644 --- a/test/extras.js +++ b/test/extras.js @@ -274,6 +274,7 @@ test('get debug name', function(t) { var e = mobx.computed(() => 3); var f = mobx.autorun(() => c.has('b')); var g = new Clazz(); + var h = mobx.observable({ b: function() {}, c: mobx.computed(function(){}) }); function name(thing, prop) { return mobx.extras.getDebugName(thing, prop); @@ -298,6 +299,9 @@ test('get debug name', function(t) { t.equal(name(g), "Clazz@9"); t.equal(name(g, "a"), "Clazz@9.a"); + t.equal(name(h, "b"), "ObservableObject@12.b"); + t.equal(name(h, "c"), "ObservableObject@12.c"); + f(); t.end(); });