Reputation: 774
Im building an app in dart using polymer.dart, and im realising i need some way to communicate between my Polymer elements. I've set my eyes upon event_bus and i am trying to make it work with polymer.
It seems however that when i try to put my PolymerElement class into my_lib i get the following error:
line 1 pos 6: url expected
part of my_lib;
^
I get that it seems like every PolymerElement should be self contained, but im having a hard time figuring out how i would handle communication from one PolymerElement to another.
So in short, what i would like to know is how do i put my elements in the same library so they can share an eventbus or what is the prefered way to handle communication between Polymer elements?
I can't seem to find any examples of communication between PolymerElements, so pointers to documentation or examples would be appreciated.
Upvotes: 3
Views: 346
Reputation: 657058
You are right, it's best to have just one Polymer element in one library and nothing else.
I use PolymerElements and EventBus.
This is no problem. You don't have to put all classes in the same library to use them.
Just import what you need.
If you have the files you want to import in your packages lib
directory import them like they were in some dependent package.
import 'package:yourpackagename/file_to_import.dart';
import 'package:yourpackagename/src/file_to_import.dart'; // just to show that other paths work too
import 'package:yourpackagename/src/someotherdir/file_to_import.dart'; // - " -
import 'package:yourpackagename/anotherdir/someotherdir/file_to_import.dart'; // - " -
If the file you want to import is in the web
directory of your application package or any subdirectory of web
use relative paths like
import 'file_to_import.dart'
import 'src/file_to_import.dart'; // just to show that other paths work too
import 'someotherdir/file_to_import.dart'; // - " -
import 'anotherdir/someotherdir/file_to_import.dart'; // - " -
After importing a library you can access all non-private classes/functions/variables like they were in the same library.
Upvotes: 3