Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: examples/js/share_echo.js

Issue 839553004: Mojo JS Bindings: Update User's Guide, examples (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: examples/js/share_echo.js
diff --git a/examples/js/share_echo.js b/examples/js/share_echo.js
new file mode 100644
index 0000000000000000000000000000000000000000..14f9789f472aff5585f3cc6b2cf84a908bf4a594
--- /dev/null
+++ b/examples/js/share_echo.js
@@ -0,0 +1,45 @@
+#!mojo:js_content_handler
+// Demonstrate using the ServiceProvider returned by the Shell
+// connectToApplication() method to provide a service to the
+// target application and to request a service from the target
+// application. To run this application with mojo_shell, set DIR
+// to be the absolute path for this directory, then:
+// mojo_shell "file://$DIR/share_echo.js file://$DIR/share_echo_target.js"
+
+define("main", [
+ "console",
+ "mojo/services/public/js/application",
+ "examples/echo/echo_service.mojom",
+], function(console, application, echo) {
+
+ var Application = application.Application;
+ var EchoService = echo.EchoService;
+
+ class EchoServiceImpl {
+ echoString(s) {
+ return Promise.resolve({value: "ShareEcho: " + s});
+ }
+ }
+
+ class ShareEcho extends Application {
+ initialize(args) {
+ if (args.length != 2) {
+ console.log("Expected URL argument");
+ return;
+ }
+ var shareEchoTargetURL = args[1];
+ // The value of targetSP is-a JS ServiceProvider that's connected to the
+ // share_echo_target.js application. We provide our implementation of
+ // EchoService to the share_echo_target.js application and request its
+ // EchoService implementation.
+ var targetSP = this.shell.connectToApplication(shareEchoTargetURL);
+ targetSP.provideService(EchoService, EchoServiceImpl);
+ var echoService = targetSP.requestService(EchoService);
+ echoService.echoString("ShareEcho").then(function(response) {
+ console.log(response.value);
+ });
+ }
+ }
+
+ return ShareEcho;
+});

Powered by Google App Engine
This is Rietveld 408576698