Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-25890] Windows: Support ES6 imports #279

Merged
merged 3 commits into from Mar 28, 2018
Merged

[TIMOB-25890] Windows: Support ES6 imports #279

merged 3 commits into from Mar 28, 2018

Conversation

infosia
Copy link
Contributor

@infosia infosia commented Mar 27, 2018

TIMOB-25890

Enable use of ES6-style imports for Windows.

// ES5-style require call
var Int32 = require('System.Int32');

// ES6-style import
import Button from 'Windows.UI.Xaml.Controls.Button';
import PropertyValue from 'Windows.Foundation.PropertyValue';
import MessageDialog from 'Windows.UI.Popups.MessageDialog';
import UICommand from 'Windows.UI.Popups.UICommand';

let win = Ti.UI.createWindow({ backgroundColor: 'green' }),
	button = new Button();

button.Content = "PUSH";
button.addEventListener('Tapped', () => {
    const dialog = new MessageDialog('My Message');
    dialog.Title = 'My Title';
    dialog.DefaultCommandIndex = 0;
    dialog.Commands.Add(new UICommand('OK', null, PropertyValue.CreateInt32(0)));
    dialog.Commands.Add(new UICommand('Cancel', null, PropertyValue.CreateInt32(1)));
    dialog.ShowAsync().then(function (command) {
        const id = Int32.cast(command.Id);
        alert((id == 0) ? 'Pushed "OK"' : 'Pushed "Cancel"')
    });
});

win.add(button);
win.open();

@hansemannn
Copy link
Contributor

Does the following statements work as well (for parity with iOS and Android)?

import { MessageDialog, UICommand } from 'Windows.UI.Popups';

@infosia
Copy link
Contributor Author

infosia commented Mar 28, 2018

@hansemannn Currently, import { MessageDialog, UICommand } from 'Windows.UI.Popups'; is not supported because in this case resulting code will be transpiled into require(package_name) such as;

var Popups = require('Windows.UI.Popups'); 
var MessageDialog = Popups.MessageDialog.

This doesn't work because Hyperloop Windows require needs fully qualified class name or enum and require against package name is not implemented yet. I don't expect this is going to be few-hours work so I'm going look into this in separate ticket.

@hansemannn
Copy link
Contributor

Ok. Is the PR ready for review then?

@infosia
Copy link
Contributor Author

infosia commented Mar 28, 2018

Yes 👍

@@ -78,10 +79,24 @@ exports.cliVersion = '>=3.2';
builder.native_types || (builder.native_types = {});
builder.native_events || (builder.native_events = {});

// Store relation between local variable name and class name
var native_specifiers = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@infosia I am wondering if we can move the Windows hooks to ES6 as well. @sgtcoolguy made huge refactoring progress in #271, but Windows haven't been touched so far. Of course this has no immediate priority!

@hansemannn
Copy link
Contributor

Asking @sgtcoolguy for review as he did something very similar on #270.

@hansemannn hansemannn added this to the v3.1.0 milestone Mar 28, 2018
@hansemannn hansemannn merged commit cb481c7 into tidev:master Mar 28, 2018
@infosia infosia deleted the TIMOB-25890 branch March 28, 2018 23:14
@infosia
Copy link
Contributor Author

infosia commented Mar 29, 2018

@hansemannn FYI I'm planning to implement multiple imports like below, which looks similar to android implementation. I would like to do like this because this makes the internal implementation simpler and easier as ".*" clearly indicates this is a package name.

import { MessageDialog, UICommand } from 'Windows.UI.Popups.*';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants