Tower
Tower

Reputation: 102915

How to handle deeper library hierarchies in Dart?

The basic usage of a library is by defining its name like:

#library('Name');

In my case, I'd like to define "nested" or "deeper" library hierarchies. So if I had a framework called Foo and let's say I build library Messenger:

#library('Messenger');

I'm afraid that would conflict with something else. What I'm looking for is something like:

#import('Foo.Messenger');

So that it's clear the messenger library is part of a Foo set of libraries.

What's the recommended way to approach this? As I understand, people would refer to your library like:

#import('package:Foo.Messenger')

Upvotes: 1

Views: 395

Answers (2)

Ladicek
Ladicek

Reputation: 6597

Librarires will change soon, see http://news.dartlang.org/2012/07/draft-spec-changes-to-library-and.html. Note that your question is answered in this document, as it says: Names of libraries intended for widespread use should follow the well known reverse internet domain name convention.

Upvotes: 1

Matt B
Matt B

Reputation: 6312

If you are concerned that your library may conflict with a namespace, then a prefix needs to be defined when using it. However you cannot force that someone else use a prefix when using your library.

To use a prefix yourself you would import like this:

#import('lib/library.dart', prefix: 'myLib');

Now anything imported from that library needs to be called as such:

var item = new myLib.SomeClass();

See this link for further details.

A package, as defined in your last night of your question, is a means of distributing and importing 3rd party libraries which may be one or many. It is still undergoing a lot of development, but it will not change how your library is called once it is imported.

See this link for information on the Pub Package manager in Dart.

Upvotes: 1

Related Questions