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

Side by Side Diff: examples/js/README.md

Issue 803173009: Mojo JS Bindings: Eliminate foo$ Stub and Proxy class members (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 12 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
« no previous file with comments | « no previous file | examples/js/wget.js » ('j') | mojo/public/js/bindings.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 JavaScript Mojo Example Applications 1 JavaScript Mojo Example Applications
2 ===================== 2 =====================
3 3
4 hello.js, world.js - A minimal application that connects to another. 4 hello.js, world.js - A minimal application that connects to another.
5 5
6 wget.js - Uses the network service to load a URL. 6 wget.js - Uses the network service to load a URL.
7 7
8 cube.js - A JS version of examples/sample_app. 8 cube.js - A JS version of examples/sample_app.
9 9
10 --- Running Mojo Applications --- 10 --- Running Mojo Applications ---
(...skipping 17 matching lines...) Expand all
28 and loading the "main" JS module and all of the modules the main module 28 and loading the "main" JS module and all of the modules the main module
29 depends on. 29 depends on.
30 30
31 This is the overall structure of a JS Mojo application: 31 This is the overall structure of a JS Mojo application:
32 32
33 #!mojo:js_content_handler 33 #!mojo:js_content_handler
34 34
35 define("main", ["mojo/services/public/js/application", 35 define("main", ["mojo/services/public/js/application",
36 <list of other modules that this application depends on> 36 <list of other modules that this application depends on>
37 ], 37 ],
38 function(appModule, <one parameter per dependent module>) { 38 function(application, <one parameter per dependent module>) {
39 class MyApplication extends appModule.Application { 39 class MyApplication extends application.Application {
40 constructor(appShell, url) { 40 constructor(appShell, url) {
41 super(appShell, url); // Initializes this.shell, this.url. 41 super(appShell, url); // Initializes this.shell, this.url.
42 // MyApplication initializations here. 42 // MyApplication initializations here.
43 } 43 }
44 44
45 initialize(args) { 45 initialize(args) {
46 } 46 }
47 47
48 acceptConnection(url, serviceProvider) { 48 acceptConnection(url, serviceProvider) {
49 } 49 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 another application. 97 another application.
98 98
99 The JS bindings for a Mojo interface's API are delivered as a JS module whose 99 The JS bindings for a Mojo interface's API are delivered as a JS module whose
100 name is based on the '.mojom' file's path. For example, to use the Mojo network 100 name is based on the '.mojom' file's path. For example, to use the Mojo network
101 service you need the JS module based on network_service.mojom: 101 service you need the JS module based on network_service.mojom:
102 102
103 define("main", [ 103 define("main", [
104 "mojo/services/network/public/interfaces/network_service.mojom", 104 "mojo/services/network/public/interfaces/network_service.mojom",
105 "mojo/services/public/js/application", 105 "mojo/services/public/js/application",
106 ] 106 ]
107 function(netModule, appModule) { 107 function(net, application) {
108 class MyApplication extends appModule.Application { 108 class MyApplication extends application.Application {
109 initialize(args) { 109 initialize(args) {
110 var netService = this.shell.connectToService( 110 var netService = this.shell.connectToService(
111 "mojo:network_service", netModule.NetworkService); 111 "mojo:network_service", net.NetworkService);
112 // Use netService's NetworkService methods. 112 // Use netService's NetworkService methods.
113 } 113 }
114 ... 114 ...
115 } 115 }
116 116
117 return MyApplication; 117 return MyApplication;
118 }); 118 });
119 119
120 The first connectToService() parameter is the Mojo URL for the network service 120 The first connectToService() parameter is the Mojo URL for the network service
121 application and the second is the JS "interface" object for NetworkService. The 121 application and the second is the JS "interface" object for NetworkService. The
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 290
291 [Client=Foo] // Redundant but always implicitly true. 291 [Client=Foo] // Redundant but always implicitly true.
292 interface Bar { 292 interface Bar {
293 } 293 }
294 294
295 interface I { 295 interface I {
296 provideFoo(Foo foo); 296 provideFoo(Foo foo);
297 requestFoo(Foo& foo); // effectively: provideFoo(Bar bar) 297 requestFoo(Foo& foo); // effectively: provideFoo(Bar bar)
298 } 298 }
299 299
300 -- In General 300 -- Stubs and Proxies
301
302 TODO: briefly introduce message pipes.
303 TODO: explain what stubs and proxies are, explain what's meant by "local" and "r emote".
304 TODO: explain the StubBindings and ProxyBindings functions.
305 TODO: support creating a proxy from a handle new MyProxy(someHandle);
306 TODO: explain the Connection object and how it relates to this stuff.
301 307
302 From a user's point of view, the bindings are in terms of the (remote) 308 From a user's point of view, the bindings are in terms of the (remote)
303 proxy class and the (local) stub class's implementation delegate 309 proxy class and the (local) stub class. Properties are added to instances
304 (internally, that's the stub class's delegate$ property). The 310 of these classes using functions called StubBindings and ProxyBindings.
305 bindings will add/use a local$ property on proxy objects which points
306 to the stub class's implementation delegate. They also manage remote$
307 property on the implementation delegate whose value is the proxy.
308 311
309 All that implies:
310
311 fooImpl.remote$.local$ == fooImpl (the stub class's delegate)
312 fooProxy.local$.remote$ == fooProxy
313 312
314 313
315 -- Callers 314 -- Callers
316 315
317 Assuming that we have a proxy for interface I, iProxy. 316 Assuming that we have a proxy for interface I, iProxy.
318 317
319 An iProxy.provideFoo() call implies that we have an implementation of 318 An iProxy.provideFoo() call implies that we have an implementation of
320 Foo, and want a proxy for Bar (Foo's client). 319 Foo, and want a proxy for Bar (Foo's client).
321 320
322 var myFooImpl; 321 var barProxy;
323 provideFoo(myFooImpl); 322 iProxy.provideFoo(function(remote) {
324 myFooImpl.remote$; // A Bar proxy initialized by provideFoo(), undefined if Fo o has no client. 323 barProxy = remote;
324 return myFooImpl;
325 });
325 326
326 An iProxy.requestFoo() call implies that we have an implementation of 327 An iProxy.requestFoo() call implies that we have an implementation of
327 Bar and want a proxy for Foo (Bar's client). 328 Bar and want a proxy for Foo (Bar's client).
328 329
329 var myBarImpl; // If Foo has no client then this is just {}. 330 var fooProxy;
330 requestFoo(myBarImpl); 331 iProxy.requestFoo(function(remote) {
331 myBarImpl.remote$; // A Foo proxy initialized by requestFoo. 332 fooProxy = remote;
333 return myBarImpl;
334 });
335
336 In the requestFoo() case, if no client were defined for Bar the function
337 parameter need not return anything.
332 338
333 The wget.js example includes a request for the URLLoader service. 339 The wget.js example includes a request for the URLLoader service.
334 340
335 -- Callees 341 -- Callees
336 342
337 An implementation of provideFoo(Foo foo) implies that we have an 343 An implementation of provideFoo(Foo foo) implies that we have an
338 implementation of Bar (Foo's client) and want a proxy to the Foo 344 implementation of Bar (Foo's client) and want a proxy to the Foo
339 that has been passed to us. 345 that has been passed to us.
340 346
341 void provideFoo(fooProxy) { 347 void provideFoo(fooProxy) {
342 fooProxy.local$ = myBarImpl; // sets myFooImpl.remote$ = fooProxy 348 ProxyBindings(fooProxy).setLocalDelegate(myMyBarImpl);
343 } 349 }
344 350
345 An implementation of requestFoo(Foo& foo) implies that we have an 351 An implementation of requestFoo(Foo& foo) implies that we have an
346 implementation of Foo and want a proxy for the Bar (Foo's client) 352 implementation of Foo and want a proxy for the Bar (Foo's client)
347 that's been passed to us. 353 that's been passed to us.
348 354
349 void requestFoo(barProxy) { 355 void requestFoo(barProxy) {
350 barProxy.local$ = myFooImpl; // sets myFooImpl.remote$ = barProxy 356 ProxyBindings(barProxy).setLocallocalDelegate(myFooImpl);
351 } 357 }
352 358
OLDNEW
« no previous file with comments | « no previous file | examples/js/wget.js » ('j') | mojo/public/js/bindings.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698