Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alterations to object by label observers #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions observers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just being curious, where were we using this information?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stringify is/was rigged to use components.getLabelForObject or components.getObjectLabel on syntax.component to consult a deserializer to rewrite the label based on which serialization it was being used in. This, if you recall, was necessary for making round trips through the serialization system.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aadsm We should figure out whether we’re still using this feature.

return emit();
}
};
}

Expand Down
31 changes: 0 additions & 31 deletions spec/expand-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");

});

});