Skip to content

Commit

Permalink
make sure computed() created properties use the correct name
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Aug 31, 2016
1 parent 2898717 commit b73f24f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/types/observableobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 4 additions & 0 deletions test/extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});
Expand Down

0 comments on commit b73f24f

Please sign in to comment.