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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!mojo:js_content_handler
2 // Demonstrate using the ServiceProvider returned by the Shell
3 // connectToApplication() method to provide a service to the
4 // target application and to request a service from the target
5 // application. To run this application with mojo_shell, set DIR
6 // to be the absolute path for this directory, then:
7 // mojo_shell "file://$DIR/share_echo.js file://$DIR/share_echo_target.js"
8
9 define("main", [
10 "console",
11 "mojo/services/public/js/application",
12 "examples/echo/echo_service.mojom",
13 ], function(console, application, echo) {
14
15 var Application = application.Application;
16 var EchoService = echo.EchoService;
17
18 class EchoServiceImpl {
19 echoString(s) {
20 return Promise.resolve({value: "ShareEcho: " + s});
21 }
22 }
23
24 class ShareEcho extends Application {
25 initialize(args) {
26 if (args.length != 2) {
27 console.log("Expected URL argument");
28 return;
29 }
30 var shareEchoTargetURL = args[1];
31 // The value of targetSP is-a JS ServiceProvider that's connected to the
32 // share_echo_target.js application. We provide our implementation of
33 // EchoService to the share_echo_target.js application and request its
34 // EchoService implementation.
35 var targetSP = this.shell.connectToApplication(shareEchoTargetURL);
36 targetSP.provideService(EchoService, EchoServiceImpl);
37 var echoService = targetSP.requestService(EchoService);
38 echoService.echoString("ShareEcho").then(function(response) {
39 console.log(response.value);
40 });
41 }
42 }
43
44 return ShareEcho;
45 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698