mojo 0.4.28

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 2

Dart Mojo Applications

Mojo Application API

TODO(zra)

Application Packaging

All Dart sources for a Mojo application are collected in a specially formatted snapshot file, which is understood by Dart's content handler in the Mojo shell. This section describes what the various parts of that package are, and how they all make it to the right place.

GN Template

Dart Mojo applications are built with the GN template 'dart_pkg' defined in //mojo/public/dart/rules.gni. Here is an example:

dart_pkg("foo") {
  app_name_override = "dart_foo"
  app = "lib/main.dart"
  sources = [
    "lib/foo.dart",
    "pubspec.yaml",
  ]
  deps = [
    ":foo_mojom",
    "//third_party/dart-pkg",
  ]
}

mojom("foo_mojom") {
  sources = [
    "foo.mojom",
  ]
}

There are several parts. See the documentation in //mojo/public/dart/rules.gni for all the details.

pub packages

Dart Mojo applications may use packages from the pub package repository at pub.dartlang.org.

The "foo" example above has uses_pub set to true. Suppose the "foo" package's pubspec.yaml is as follows:

name: foo
version: 0.0.1
description: Foo
dependencies:
  crypto: ">=0.9.0 <0.10.0"

The script //mojo/public/tools/git/dart_pub_get.py should be run before build time, e.g. as a "runhooks" action during gclient sync. The script traverses a directory tree looking for pubspec.yaml files. On finding one, in the containing directory, it runs pub get. This creates a "packages/" directory in the source tree adjacent to the pubspec.yaml file containing the downloaded Dart packages. pub get also creates a pubspec.lock file that locks down pub packages to specific versions. This pubspec.lock file must be checked in in order to have hermetic builds.

During the build, The dart_pkg rule looks for a "packages/" directory, and ensures that its contents are available when running the application.

Generated bindings

The script //mojo/public/tools/bindings/generators/mojom_dart_generator.py and the templates under //mojo/public/tools/bindings/generators/dart_templates govern how .mojom files are compiled into Dart code.

Consider the foo.mojom file used by our example:

[DartPackage="foo"]
module foo;

struct Foo {
  int32 code;
  string? description;
};

This contents of this file are in the foo module. The Dart source generated for this file will end up under, e.g. //out/Debug/gen/dart- pkg/foo/lib/foo/network_error.mojom.dart, along with the other Dart sources generated for .mojom files with the "foo" DartPackage annotation in the foo module.

Resulting file

The dart_pkg rule has two results. The first result is a Dart snapshot file zipped up into a .mojo file in the build output directory---something like //out/Release/foo.mojo. This file is understood by the Dart content handler and is suitable for deployment. The second result is a directory layout of the "foo" app that can be served by a webserver. When the URL of lib/main.dart is given to the mojo_shell, the app will be run in the Dart content handler.

They layout for our "foo" example will be the following:

//lib/main.dart
//lib/foo.dart
//lib/foo/foo.mojom.dart
//packages/crypto/...  # Dart's crypto pub package.
//packages/mojo/...  # Mojo SDK Dart libraries.

Where //packages/mojo contains Dart's Mojo bindings, //packages/crypto contains the crypto pub package, and //lib/foo/ contains the bindings generated for foo.mojom.

Mojo's Dart content handler sets the package root for a Dart application to be the packages directory. Therefore, Dart sources in this application can use the following imports:

import 'package:crypto/crypto.dart';
import 'package:foo/foo/foo.mojom.dart';
import 'package:mojo/application.dart';

0.4.28

MOJO_SDK: 56ddb774e386f2e021b1ac58965db050b0e5353c

0.4.27

MOJO_SDK: 9397aa588d55e96077c3859d4a136e4e6adf57ea

0.4.26

MOJO_SDK: 38c5dbd1426e105d42d6b070b8e4089c9db957eb

0.4.25

MOJO_SDK: ee5b33cba0face525d425d6bd8682e5de038ad73

0.4.24

MOJO_SDK: ff47297bfaed2660b106a67d6693343b0bc8356b

0.4.23

MOJO_SDK: ef5cd660ec6f1c50eaff62c81ea7662662d04e15

0.4.22

MOJO_SDK: f56fd59ec51e1ecdd52fb848ceff1b6b6fe7f7fa

0.4.21

MOJO_SDK: c200560ac45a79b61b8e8c0444af471789f5669f

0.4.20

MOJO_SDK: 705723c25a51b30a89b6431a6377b09e4069561e

0.4.19

MOJO_SDK: 7c72e53d105c346dd82cbdbeb12d9e3f0712093d

0.4.18

MOJO_SDK: 31c5037ab2c63649632c9f2d4227ebe6f22015a4

0.4.17

MOJO_SDK: 1484e831758d05c7af0f27c199d24e3bbdc6383f

0.4.16

MOJO_SDK: 1308cd12434c9536a28592ff09399a57ef7f4f77

0.4.15

MOJO_SDK: c9e15130499cc859050668ea6f78485001c96251

0.4.14

MOJO_SDK: b3aaccc8d9408bc645ee633e7030c605f333be95

0.4.13

MOJO_SDK: 2ae2bccb82f37947c69ab5d6e06c2d109690a394

0.4.12

MOJO_SDK: ebf435275996a69482ea342aa3ae881aecd6c90e

0.4.11

MOJO_SDK: 3f50c60f8af5bb485f248ceea2407a59f09caad5

0.4.10

0.4.9

0.4.8

0.4.7

0.4.6

0.4.5

0.4.4

0.4.3

0.4.2

0.4.1

0.3.2

0.3.1

0.3.0

0.2.1

0.2.0

0.1.0

0.0.25

0.0.23

0.0.22

0.0.18

0.0.17

0.0.16

0.0.15

0.0.14

0.0.13

0.0.12

0.0.11

0.0.10

0.0.8

  • Update version to match sky package. 0.0.7 was skipped.

0.0.6

  • Fix interface name capitalization bug in Dart bindings
  • Add support for interface control messages (queryVersion, requireVersion)

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  mojo: ^0.4.28

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:mojo/application.dart';
import 'package:mojo/bindings.dart';
import 'package:mojo/core.dart';
  
Version Uploaded Documentation Archive
0.4.28 Aug 17, 2016 Go to the documentation of mojo 0.4.28 Download mojo 0.4.28 archive
0.4.27 Jul 1, 2016 Go to the documentation of mojo 0.4.27 Download mojo 0.4.27 archive
0.4.26 Jun 28, 2016 Go to the documentation of mojo 0.4.26 Download mojo 0.4.26 archive
0.4.25 Jun 13, 2016 Go to the documentation of mojo 0.4.25 Download mojo 0.4.25 archive
0.4.24 Jun 2, 2016 Go to the documentation of mojo 0.4.24 Download mojo 0.4.24 archive
0.4.23 May 23, 2016 Go to the documentation of mojo 0.4.23 Download mojo 0.4.23 archive
0.4.22 May 18, 2016 Go to the documentation of mojo 0.4.22 Download mojo 0.4.22 archive
0.4.21 May 13, 2016 Go to the documentation of mojo 0.4.21 Download mojo 0.4.21 archive
0.4.20 May 6, 2016 Go to the documentation of mojo 0.4.20 Download mojo 0.4.20 archive
0.4.19 Apr 7, 2016 Go to the documentation of mojo 0.4.19 Download mojo 0.4.19 archive

All 34 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
3
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
2
Learn more about scoring.

We analyzed this package on Aug 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.11.8

Platforms

Detected platforms: Flutter, other

Platform components identified in package: isolate.

Issues and suggestions

Fix lib/src/codec.dart.

Analysis of lib/src/codec.dart failed with 35 errors, including:

line 73 col 44: Undefined name 'Endianness'.

line 152 col 54: Undefined name 'Endianness'.

line 158 col 53: Undefined name 'Endianness'.

line 162 col 54: Undefined name 'Endianness'.

line 168 col 53: Undefined name 'Endianness'.

Fix lib/mojo/bindings/types/service_describer.mojom.dart.

Analysis of lib/mojo/bindings/types/service_describer.mojom.dart failed with 3 errors:

line 836 col 60: The getter 'ROOT' isn't defined for the class 'Zone'.

line 861 col 60: The getter 'ROOT' isn't defined for the class 'Zone'.

line 885 col 60: The getter 'ROOT' isn't defined for the class 'Zone'.

Homepage does not exists.

We were unable to access https://github.com/domokit/mojo at the time of the analysis.

Add SDK constraint in pubspec.yaml.

For information about setting SDK constraint, please see https://www.dartlang.org/tools/pub/pubspec#sdk-constraints.

Fix additional 22 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/service_describer.dart (1 error)
  • lib/mojo/application.mojom.dart (Run dartfmt to format lib/mojo/application.mojom.dart.)
  • lib/mojo/application_connector.mojom.dart (Run dartfmt to format lib/mojo/application_connector.mojom.dart.)
  • lib/mojo/bindings/types/mojom_files.mojom.dart (Run dartfmt to format lib/mojo/bindings/types/mojom_files.mojom.dart.)
  • lib/mojo/bindings/types/mojom_types.mojom.dart (Run dartfmt to format lib/mojo/bindings/types/mojom_types.mojom.dart.)
  • lib/mojo/http_header.mojom.dart (Run dartfmt to format lib/mojo/http_header.mojom.dart.)
  • lib/mojo/interface_control_messages.mojom.dart (Run dartfmt to format lib/mojo/interface_control_messages.mojom.dart.)
  • lib/mojo/network_error.mojom.dart (Run dartfmt to format lib/mojo/network_error.mojom.dart.)
  • lib/mojo/service_provider.mojom.dart (Run dartfmt to format lib/mojo/service_provider.mojom.dart.)
  • lib/mojo/shell.mojom.dart (Run dartfmt to format lib/mojo/shell.mojom.dart.)
  • lib/mojo/url_request.mojom.dart (Run dartfmt to format lib/mojo/url_request.mojom.dart.)
  • lib/mojo/url_response.mojom.dart (Run dartfmt to format lib/mojo/url_response.mojom.dart.)
  • lib/src/application.dart (Run dartfmt to format lib/src/application.dart.)
  • lib/src/application_connection.dart (Run dartfmt to format lib/src/application_connection.dart.)
  • lib/src/buffer.dart (Run dartfmt to format lib/src/buffer.dart.)
  • lib/src/event_handler.dart (Run dartfmt to format lib/src/event_handler.dart.)
  • lib/src/event_subscription.dart (Run dartfmt to format lib/src/event_subscription.dart.)
  • lib/src/handle.dart (Run dartfmt to format lib/src/handle.dart.)
  • lib/src/internal.dart (Run dartfmt to format lib/src/internal.dart.)
  • lib/src/proxy.dart (Run dartfmt to format lib/src/proxy.dart.)
  • lib/src/struct.dart (Run dartfmt to format lib/src/struct.dart.)
  • lib/src/stub.dart (Run dartfmt to format lib/src/stub.dart.)

Package is getting outdated.

The package was released 103 weeks ago.

The description is too short.

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v1 release.

While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction of the API.

Maintain an example.

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use mojo.dart.