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

Unified Diff: examples/js/share_echo_target.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_target.js
diff --git a/examples/js/share_echo_target.js b/examples/js/share_echo_target.js
new file mode 100644
index 0000000000000000000000000000000000000000..db59fccad2e14ed1d7ad8766b2f1f294fdde075d
--- /dev/null
+++ b/examples/js/share_echo_target.js
@@ -0,0 +1,36 @@
+#!mojo:js_content_handler
+// Demonstrate sharing services via application ServiceProviders.
+// This application is launched by share_echo.js. It both provides
+// and requests an EchoService implementation.
+//
+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: "ShareEchoTarget: " + s});
+ }
+ }
+
+ class ShareEchoTarget extends Application {
+ acceptConnection(initiatorURL, shareEchoSP) {
+ // The shareEchoSP parameter is-a JS ServiceProvider that's
+ // connected to the share_echo.js application. We can request the
+ // share_echo.js implementation of EchoService and provide the
+ // share_echo.js application with our own EchoService implementation.
+ var echoService = shareEchoSP.requestService(EchoService);
+ echoService.echoString("ShareEchoTarget").then(function(response) {
+ console.log(response.value);
+ });
+ shareEchoSP.provideService(EchoService, EchoServiceImpl);
+ }
+ }
+
+ return ShareEchoTarget;
+});
« examples/js/cube.js ('K') | « examples/js/share_echo.js ('k') | examples/js/users-guide.md » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698