1

I'm looking for a framework that will allow me to write a SPA and a embeddable library. I would love to have a way to share component between both. So I'm looking for a solution that has relatively small amount of potential conflicts with other frameworks and with AngularDart it self. Including case when library has been included using script tab, yes two versions of AngularDart on the same page. A framework that has less Global Objects, no Standard Object overrides, no Global Event handling and limited polyfill conflicts.

Dart and AngularDart seams what I need, but I also need more details and docs to validate my assumptions. Anything you are able to point out would be very helpful and greatly appreciated (issues, PR, blogs , roadmap, commits, specs, docs)

It's possible to run multiple AngularDart apps on the same page. I've tested AngularDart todo example app embedded in itself. But I need more details on what dart2js is doing and how compiler avoids global scope pollution.

como eStas
  • 43
  • 3
  • I think AngularDart doesn't support multiple applications. Dart also isn't a good fit for creating libraries to be used in JavaSrcript. I wouldn't expect issues with the other bullets. – Günter Zöchbauer Feb 04 '18 at 15:00
  • @GünterZöchbauer, yes, you are maybe right. But my library is not going to be open sourced or open for extension. I just want a set of components wrapped into the limited JS API (which is the only way to use them) that could be included as a package dependency and/or as a script tag. Most importantly **it should not brake host application** because it uses the same framework or polyfill. Which is the issue I'm having with JS Angular 2 - 5 and Zone.js (yes I can try to `{ngZone: 'noop'}`, bud than Material UI components are not guaranteed to work yet). – como eStas Feb 05 '18 at 04:19
  • If you run `dart2js` a significant amount of "framework" code is compiled into the output to emulate Dart features, also browser abstraction code. Every compilation output contains that part. It cant be shared because it's subject to tree-shaking which means not every output contains the exact same parts of this code. – Günter Zöchbauer Feb 05 '18 at 04:24
  • Very interesting! I don't what to share the framework only my AngularDart based components. And, I don't mind to have two versions of AngularDart frameworks if they continue to work. Though this comment rises a question, is there potential for a conflict between produced JS output of framework code if I compile two different AngularDart projects and stick them on one page? Now, I say potential because I was able to take provided todo example compile it as two separate projects and include one into another using ` – como eStas Feb 05 '18 at 06:02
  • How exactly `dart2js` avoids conflicts between produced JS output of Dart runtime and framework code if someone will compile two different AngularDart projects and stick them on the same page? – como eStas Feb 05 '18 at 06:09
  • They are each in their own script tag. As far as I know there is no danger of conflict as long as they don't create properties on the `window` object which I don't think Dart or Angular do by itself. – Günter Zöchbauer Feb 05 '18 at 06:14

1 Answers1

0

Yes, AngularDart should be well suited for your requirements.

Dart itself shouldn't pollute your scope at all, you can try running dart2js on something trivial (like just print inside main) and verify the code - it creates a closure and executes it, so nothing inside is accessible from outside. There is also no patching of any global JS objects, so you can run it alongside anything without interference. If it's not the case file a bug.

You can run as many AngularDart applications on a single page as you wish. To get them fully isolated you can compile each one separately with dart2js, then they wouldn't be able to access any of each other internals whatsoever.

rkj
  • 8,787
  • 2
  • 29
  • 35