关于跨平台项目中网络语言互操作性的问题 [英] Questions about web-languages interoperability in a cross-plateform project

查看:27
本文介绍了关于跨平台项目中网络语言互操作性的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算用 AngularJS 在 iOS、Android 和网站上创建一个应用程序.

但由于不必在每个应用程序上重写业务代码,我想尽可能多地重用代码.

为了能够在任何平台上执行项目的核心,我必须使用网络语言.

通过不同的文章,我计划了一个通用架构来分离项目的业务逻辑 - 核心 - 与将为每个系统重新实现的 UI(iOS 的 UIKit、Web 应用的 AngularJS 和 Polymer 等)

此架构的目标是尊重重要的软件工程原则,例如

这里是 AngularJS:

<小时>

既然您已经了解了有关架构的所有信息,下面是我的问题.

我没有足够的网络语言经验和反馈,无法做出明智的选择.经过一番研究,我发现有多种选择:

  • 飞镖:

    • 问题 1: 是否存在允许通过 VM 在 Objective-C/Swift 和 Java 之间进行互操作的机制?我知道这两个平台都有 VM 来执行 Javascript 代码,而 Google 提供 dart2js 来将 Dart 编译为 Javascript 代码.但这不是普通的 Javascript:请参阅这里的示例.所以我不知道是否还有适当的互操作性.
  • Javascript ES6: 事件如果尚未在浏览器中完全实现,则可以通过 Traceur 编译器.

    • 问题二: Traceur 编译的 Javascript 与 iOS/Android 中的 VM 是否有互操作性?
    • 问题三:通过 Traceur 使用 ES6 开发大型项目并有生产代码是否安全"?

感谢您的阅读.

解决方案

我知道这不是您列出的选项之一,但不会自动排除 C++.这就是 Dropbox 使用的例子,他们甚至为此目的开源了他们的工具:

C++ 到 Java/Objective-C API 生成器:

https://github.com/dropbox/djinni

适用于 Android/iOS 的原生"应用示例:

https://github.com/libmx3/mx3

有关该主题的有趣文章以及更多链接:

http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cross-platform-development/

更新答案:

如果您真的不想使用 C++,并且可以接受非本地化带来的臃肿问题,那么您可以尝试以下方法:

https://github.com/MobileChromeApps/mobile-chrome-apps

该项目是 Google 的 Cordova 分支,并添加了许多新功能和优势.

这里有一个 Chrome API 的 Dart 包装器:

https://github.com/dart-gde/chrome.dart

基本上,您可以使用纯 HTML5 技术在 Dart 中编写应用程序,然后在某些事情上使用 Chrome API(设备状态等).然后就可以部署了:

  • Web:在没有 Chrome API 功能的情况下编译为 JavaScript.
  • Chrome 操作系统:使用 Chrome API 功能编译为 JavaScript.
  • Android:编译为 JavaScript,然后使用 MobileChromeApps 创建 Android 应用.
  • iOS:编译成 JavaScript,然后使用 MobileChromeApps 创建 iOS 应用.

I plan to create an application on iOS, Android and a website with AngularJS.

But for not having to rewrite the business code on each app, I would like to reuse as much code as possible.

To be able to execute the core of the project on any platform, I have to use a web language.

Through different articles, I plan a common architecture to separate the business logic of the project - core - with the UI which will reimplemented for each system (UIKit for iOS, AngularJS and Polymer for the webapp, etc.)

The goal of this architecture is to respect important software engineering principles such as information hiding by decomposing requirements in modules, DRY and SOLID

  • Each feature will be decomposed in module.
  • Core: Business logic code - reusable on every platform - will be represented in form of a library.
  • View: The view class will be developed on each different platform to use the different UI elements proposed on each platform. E.g.: subclass of a ViewController in Objective-C / Swift for iOS or a simple class to manipulate HTML for the web-app. There is no logic in this class. It is only responsible to:
    • Handle user interactions to the business logic.
    • Display contents from the business logic
  • IView: Interface which abstracts the class which manipulates the view.
  • Presenter: Link between the Interactor and the View to drive the UI.
  • Interactor: The logic of the module, such as algorithms.
  • Data Store: Manage the persistence and the fetching of data by communicating with a database or API or web-service.
  • Model: Data represented in structures.

Here for iOS (almost the same for Android):

The code of "core" will be executed through a virtual machine as this article shows us: http://www.skyscanner.net/blogs/developing-mobile-cross-platform-library-part-3-javascript

Here for AngularJS:


Now that you know everything about the architecture, here are my questions.

I don't have enough experiences and feedback on the web-langages to be able to make a smart choice. After few researches, I found that there are various options:

  • Dart:

    • Question 1: Are there mechanisms to allow interoperability between Objective-C/Swift and Java through VM? I know that both platforms have VM to execute Javascript code and Google provides dart2js to compile Dart to Javascript code. But it's not plain Javascript: See an example here. So I don't know if there is still a proper interoperability.
  • Javascript ES6: Event if it's not fully implemented in browsers yet, it's possible to start using ES6 with Traceur compiler.

    • Question 2: Is there interoperability of Javascript compiled by Traceur and the VM in iOS/Android?
    • Question 3: Is it "safe" to use ES6 through Traceur to develop a large-scale project and have production code?

Thank you for reading.

解决方案

I know this wasn't one of the options you listed but don't automatically rule out C++. This is what Dropbox uses for example, they even open sourced their tools for this purpose:

C++ to Java/Objective-C API generator:

https://github.com/dropbox/djinni

Sample "native" app for Android/iOS:

https://github.com/libmx3/mx3

Interesting article on the subject with more links:

http://oleb.net/blog/2014/05/how-dropbox-uses-cplusplus-cross-platform-development/

Updated Answer:

If you really don't want to use C++ and are okay with the bloat you'll get from going non-native then you can try the following:

https://github.com/MobileChromeApps/mobile-chrome-apps

That project is Google's fork of Cordova and adds a bunch of new features and benefits.

There is a Dart wrapper over Chrome APIs here:

https://github.com/dart-gde/chrome.dart

Basically, you would write your app in Dart using plain HTML5 technologies, then for certain things you'd use the Chrome APIs (device state, etc). Then you can deploy:

  • Web: Compile to JavaScript without the Chrome API features.
  • Chrome OS: Compile to JavaScript with Chrome API features.
  • Android: Compile to JavaScript and then use MobileChromeApps to create Android app.
  • iOS: Compile to JavaScript and then use MobileChromeApps to create iOS app.

这篇关于关于跨平台项目中网络语言互操作性的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆