Commit 841e44fe authored by Bo Majewski's avatar Bo Majewski Committed by Commit Bot

File SWA: Switch to using modules

Use modules to load main class and browser proxy. Actually calls browser
proxy.

Bug: 1113981
Change-Id: Ia5df25c26c8e2131cab9663382680156e1304b75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2497901
Commit-Queue: Bo Majewski <majewski@chromium.org>
Reviewed-by: default avatarAlex Danilo <adanilo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821071}
parent c928f70f
......@@ -15,5 +15,6 @@ js_library("main_js") {
}
js_type_check("closure_compile") {
uses_js_modules = true
deps = [ ":main_js" ]
}
......@@ -2,7 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
class BrowserProxy {
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import './file_manager.mojom-lite.js';
export class BrowserProxy {
constructor() {
/** @type {chromeos.fileManager.mojom.PageCallbackRouter} */
this.callbackRouter = new chromeos.fileManager.mojom.PageCallbackRouter();
......@@ -15,7 +18,3 @@ class BrowserProxy {
this.handler.$.bindNewPipeAndPassReceiver());
}
}
// For demo purpose a global variable is fine I guess.
// I'll defer to people who know how to JS to do it in a proper way.
const theBrowserProxy = new BrowserProxy();
......@@ -9,12 +9,7 @@
<meta charset="utf-8">
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<link rel="stylesheet" href="main.css">
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js">
</script>
<script src="chrome://file-manager/file_manager.mojom-lite.js"></script>
<script src="chrome://file-manager/browser_proxy.js"></script>
<script src="chrome://file-manager/main.js"></script>
<script type="module" src="chrome://file-manager/main.js"></script>
</head>
<body>
<h1>File Manager WebUI Demo</h1>
......
......@@ -2,24 +2,46 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Basic example of establishing comms with the backend.
import {BrowserProxy} from './browser_proxy.js'
// There must be only one listener returning values.
theBrowserProxy.callbackRouter.getBar.addListener((foo) => {
console.log('GetBar(' + foo + ')');
return Promise.resolve({bar: 'baz'});
});
/**
* Represents file manager application. Starting point for the application
* interaction.
*/
class FileManagerApp {
constructor() {
console.info('File manager app created ...');
}
// Listen-only callbacks can be multiple.
theBrowserProxy.callbackRouter.onSomethingHappened.addListener(
(something, other) => {
console.log('OnSomethingHappened(' + something + ', ' + other + ')');
});
theBrowserProxy.callbackRouter.onSomethingHappened.addListener(
(something, other) => {
console.log('eh? ' + something + '. what? ' + other);
run() {
// Basic example of establishing communication with the backend.
const browserProxy = new BrowserProxy();
// There must be only one listener returning values.
browserProxy.callbackRouter.getBar.addListener((foo) => {
console.log('GetBar(' + foo + ')');
return Promise.resolve({bar: 'baz'});
});
// Listen-only callbacks can be multiple.
browserProxy.callbackRouter.onSomethingHappened.addListener(
(something, other) => {
console.log('OnSomethingHappened(' + something + ', ' + other + ')');
});
browserProxy.callbackRouter.onSomethingHappened.addListener(
(something, other) => {
console.log('eh? ' + something + '. what? ' + other);
});
// Show the interaction via Mojo.
window.setTimeout(() => {
browserProxy.handler.setFoo('foo-value');
browserProxy.handler.doABarrelRoll();
}, 1000);
}
}
const app = new FileManagerApp();
document.addEventListener('DOMContentLoaded', () => {
console.info('File manager launched ...');
app.run();
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment