diff --git a/observers.js b/observers.js index 15cb613..5207a4b 100644 --- a/observers.js +++ b/observers.js @@ -43,13 +43,14 @@ function makeElementObserver(id) { exports.makeComponentObserver = makeComponentObserver; function makeComponentObserver(label, syntax) { return function observeComponent(emit, scope) { - // TODO error if scope.components does not exist or components for - // label does not exist var components = scope.components; - var method = components.getObjectByLabel || components.getComponentByLabel; - var component = method.call(components, label); - syntax.component = component; - return emit(component); + if (components && typeof components.observeObjectByLabel === "function") { + return components.observeObjectByLabel(label, emit, scope); + } else if (components && typeof components.getObjectByLabel === "function") { + return emit(components.getObjectByLabel(label)); + } else { + return emit(); + } }; } diff --git a/spec/expand-spec.js b/spec/expand-spec.js index f2740fe..1500e44 100644 --- a/spec/expand-spec.js +++ b/spec/expand-spec.js @@ -73,36 +73,5 @@ describe("expand", function () { }); }); - - it("should expand component labels from a serializer", function () { - - var syntax = parse("@a"); - var a = {}; - var observe = compileObserver(syntax); - var scope = new Scope(); - scope.components = { - getObjectByLabel: function (label) { - expect(label).toBe("a"); - return a; - } - }; - var cancel = observe(function (_a) { - expect(_a).toBe(a); - }, scope); - - expect(syntax.component).toBe(a); - - var scope = new Scope(); - scope.components = { - getObjectLabel: function (_a) { - expect(_a).toBe(a); - return "b"; - }, - }; - var syntax = expand(syntax, scope); - expect(stringify(syntax)).toBe("@b"); - - }); - });