Skip to content

Commit

Permalink
replace dynamic imports with static imports for better cross-browser …
Browse files Browse the repository at this point in the history
…support
  • Loading branch information
jonagh committed Feb 23, 2019
1 parent 4922966 commit 16ee5bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
14 changes: 5 additions & 9 deletions commands.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const commandModules = [
//import('./commands/example.js'),
import('./commands/findOutOfAlbumPhotos.js')
];
//import example from './commands/example.js';
import findOutOfAlbumPhotos from './commands/findOutOfAlbumPhotos.js';

export default Promise.all(commandModules).then(modules => {
// Use default import of modules,
// changing an array of Modules into an array of the actual exports.
return modules.map(m => m.default);
});
export default [
findOutOfAlbumPhotos
]
38 changes: 17 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import auth from './auth.js';
import ui from './ui.js';
import commandsLoader from './commands.js';

commandsLoader.then(commands => {
// Commands should be an array of 'command' objects,
// which should have the properties: { name, desc, scopes, run }.

// Set command options into UI.
ui.state.commands = commands.map((c, i) => { return { value: i, text: c.name }; });

// On button click run the selected command, the <select>.value is the index into the commands array.
ui.elements.buttonRunCommand.addEventListener('click', () => runCommand(commands[ui.elements.selectCommands.value]));

return distillCommandScopes(commands);
})
.then(gapiScopes => {
ui.init((gapiClientId) => {
if (gapiClientId) {
auth.init(gapiClientId, gapiScopes, (userDisplayIdentity) => { ui.state.identity = userDisplayIdentity; });
auth.renderButton(ui.elements.containerSigninButton.id, gapiScopes);
}
});

// Commands should be an array of 'command' objects,
// which should have the properties: { name, desc, scopes, run }.
import commands from './commands.js';

// Set command options into UI.
ui.state.commands = commands.map((c, i) => { return { value: i, text: c.name }; });
// On button click run the selected command, the <select>.value is the index into the commands array.
ui.elements.buttonRunCommand.addEventListener('click', () => runCommand(commands[ui.elements.selectCommands.value]));

const gapiScopes = distillCommandScopes(commands);
// Initialize the UI and then initialize Auth (with gapi & scopes).
ui.init((gapiClientId) => {
if (gapiClientId) {
auth.init(gapiClientId, gapiScopes, (userDisplayIdentity) => { ui.state.identity = userDisplayIdentity; });
auth.renderButton(ui.elements.containerSigninButton.id, gapiScopes);
}
});

async function runCommand(selectedCommand) {
Expand Down

0 comments on commit 16ee5bf

Please sign in to comment.