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

LibraryDependencyMirror API feedback #17742

Closed
jbdeboer opened this issue Mar 24, 2014 · 1 comment
Closed

LibraryDependencyMirror API feedback #17742

jbdeboer opened this issue Mar 24, 2014 · 1 comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-mirrors type-enhancement A request for a change that isn't a bug

Comments

@jbdeboer
Copy link

We are using the LibraryDependencyMirror API to reflect on exported symbols, ensuring that we do not pollute the global namespace.

It works; thank you! Some feedback:

See our use case here: https://github.com/angular/angular.dart/blob/18c11147ad74034c65e959c0d19183ee4c8fd6f0/test/angular_spec.dart

* Suggestion 1: *

Implement a "LibraryViewMirror" which returns a LibraryMirror containing all the symbols visible as the library was imported. e.g.

import "package:angular/angular.dart";
currentMirrorSystem().findLibraryView(new Symbol("angular")).declarations;

e.g.

import "package:angular/angular.dart" show Parser;
currentMirrorSystem().findLibraryView(new Symbol("angular")).declarations;

Here, the declarations list would be [Parser];

Instead, I wrote a function that recurses over the library export tree and calculates a list of symbols exported from the library.

The combinators mirror proved somewhat difficult to work with. I used them to filter the list of symbols exported from a library.

* Suggestion 2: *

I would have preferred a explicit lists:

List<Symbol> get LibraryDependencyMirror.shownSymbols
List<Symbol> get LibraryDependencyMirror.hiddenSymbols

Instead I built that list by iterating over the combinators list. In my case CombinatorMirror.identifiers was always a list of a single element, which was confusing.

* Suggestion 3: *

Rename CombinatorMirror.identifiers to CombinatorMirror.identifier, making it a non-list.

Then I could implement a shownSymbols list using List methods (map, where):
shownSymbols = libDeps.combinators.where((c) => c.isShow).map((c) => c.identifier);

OR

Have LibraryDependencyMirror.combinators be a list of 0 or 1 elements, and have CombinatorMirror.identifiers contain all the hidden or shown symbols.

Them I could implement a shownSymbols list trivially:
shownSymbols = libDeps.combinators.isEmpty || !libDeps.combinators[0].isShow ? [] : libDeps.combinators[0].identifiers;

@floitschG
Copy link
Contributor

Added Area-Library, Library-Mirrors, Triaged labels.

@jbdeboer jbdeboer added Type-Enhancement area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors labels Mar 25, 2014
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed priority-unassigned labels Feb 29, 2016
@matanlurey matanlurey added the closed-obsolete Closed as the reported issue is no longer relevant label Mar 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-obsolete Closed as the reported issue is no longer relevant library-mirrors type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants