Jscex Win8 import

12 views
Skip to first unread message

鸣峰 汪

unread,
May 11, 2012, 2:42:50 AM5/11/12
to Jscex User Groups
老赵,您好!

我希望在Win8上或是浏览器,或是Metro中使用Jscex.

Win8 VS11 Metro app 非 default.html的 html中

已导入 <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-parser.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-jit.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-builderbase.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-async.js"></script>

在对应的js中 无法直接获得 Jscex 对象, console 输出为 CommonJS isWrapping 类型
遂用 require 获得Jscex 对象 但无法加载jit 和async 模块 require("jscex-
jit") require("jscex-async")
请问有何解决方法 ?谢谢!

Jeffrey Zhao

unread,
May 12, 2012, 9:15:14 AM5/12/12
to Jscex User Groups
���õ����ĸ�ģ�����������

���мǵü���jscex-async-winrt.js������ΪWinRT�����׼���ġ�


Jeffrey Zhao
Blog: http://blog.zhaojie.me/
Twitter: @jeffz_cn (Chinese) | @jeffz_en (English)
-----Original Message-----
From: ��� ��
Sent: Friday, May 11, 2012 2:42 PM
To: Jscex User Groups
Subject: [jscex] Jscex Win8 import

���ԣ���ã�

��ϣ����Win8�ϻ��������������Metro��ʹ��Jscex.

Win8 VS11 Metro app �� default.html�� html��

�ѵ��� <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-parser.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-jit.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-builderbase.js"></script>
<script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-async.js"></script>

�ڶ�Ӧ��js�� �޷�ֱ�ӻ�� Jscex ���� console ���Ϊ CommonJS
isWrapping ����
���� require ���Jscex ���� ���޷�����jit ��async ģ��
require("jscex-
jit") require("jscex-async")
�����кν������ ��лл��

汪鸣峰

unread,
May 12, 2012, 10:34:45 AM5/12/12
to js...@googlegroups.com
老赵,您好!
            如果是winRT下jscex-async-winrt 是需要额外加载的还是是用来替换jscex-async的?
            现在我是在metro app 中直接调用winJS出现的上述问题

在 2012年5月12日 下午9:15,Jeffrey Zhao <je...@live.com>写道:
你用的是哪个模块加载器啊?

还有记得加载jscex-async-winrt.js,这是为WinRT编程下准备的。



Jeffrey Zhao
Blog: http://blog.zhaojie.me/
Twitter: @jeffz_cn (Chinese) | @jeffz_en (English)
-----Original Message----- From: 鸣峰 汪

Sent: Friday, May 11, 2012 2:42 PM
To: Jscex User Groups
Subject: [jscex] Jscex Win8 import
老赵,您好!

      我希望在Win8上或是浏览器,或是Metro中使用Jscex.

        Win8 VS11 Metro app  非 default.html的 html中

        已导入            <script type="text/javascript" src="../

JeffreyZhao-jscex/src/jscex.js"></script>
                              <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-parser.js"></script>
                              <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-jit.js"></script>
                              <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-builderbase.js"></script>
                              <script type="text/javascript" src="../
JeffreyZhao-jscex/src/jscex-async.js"></script>

        在对应的js中 无法直接获得 Jscex 对象, console 输出为  CommonJS isWrapping 类型
        遂用 require 获得Jscex 对象  但无法加载jit 和async 模块 require("jscex-

jit")   require("jscex-async")
        请问有何解决方法 ?谢谢!

Jeffrey Zhao

unread,
May 12, 2012, 10:59:27 AM5/12/12
to js...@googlegroups.com
jscex-winrt-async用来代替jscex-async以及jscex-async-powerpack。
 
按理说可以直接使用才对,我是这么用的,我明天写个简单的示例给你看。
 
Jeffrey Zhao
Blog: http://blog.zhaojie.me/
Twitter: @jeffz_cn (Chinese) | @jeffz_en (English)

Jeffrey Zhao

unread,
May 14, 2012, 9:18:15 AM5/14/12
to js...@googlegroups.com
这是个最简单的例子,里面所有的Jscex文件都打包成了一个,可以打开看头部注释。使用代码如下:
 
(function () {
 
    var MessageDialog = Windows.UI.Popups.MessageDialog;
    var UICommand = Windows.UI.Popups.UICommand;
    var FileOpenPicker = Windows.Storage.Pickers.FileOpenPicker;
    var PickerViewMode = Windows.Storage.Pickers.PickerViewMode;
    var PickerLocationId = Windows.Storage.Pickers.PickerLocationId;
    var FileAccessMode = Windows.Storage.FileAccessMode;
 
    WinJS.Namespace.define("MyApp", {
        showPhoto: eval(Jscex.compile("winrt-async", function () {
            var dlg = new MessageDialog("Do you want to open a file?");
            dlg.commands.push(new UICommand("Yes", null, "Yes"));
            dlg.commands.push(new UICommand("No", null, "No"));
 
            var result = $await(dlg.showAsync());
            if (result.id == "Yes") {
                var picker = new FileOpenPicker();
                picker.viewMode = PickerViewMode.thumbnail;
                picker.suggestedStartLocation = PickerLocationId.picturesLibrary;
                picker.fileTypeFilter.push(".jpg");
 
                var file = $await(picker.pickSingleFileAsync());
                if (file != null) {
                    document.getElementById("myImg").src = URL.createObjectURL(file);
                }
            }
        }))
    });
 
})();
 
不用Jscex的等价代码:
 
(function () {
 
    var MessageDialog = Windows.UI.Popups.MessageDialog;
    var UICommand = Windows.UI.Popups.UICommand;
    var FileOpenPicker = Windows.Storage.Pickers.FileOpenPicker;
    var PickerViewMode = Windows.Storage.Pickers.PickerViewMode;
    var PickerLocationId = Windows.Storage.Pickers.PickerLocationId;
    var FileAccessMode = Windows.Storage.FileAccessMode;
 
    WinJS.Namespace.define("MyApp", {
        showPhoto: function () {
            var dlg = new MessageDialog("Do you want to open a file?");
            dlg.commands.push(new UICommand("Yes", null, "Yes"));
            dlg.commands.push(new UICommand("No", null, "No"));
 
            dlg.showAsync().then(function (result) {
                if (result.id == "Yes") {
                    var picker = new FileOpenPicker();
                    picker.viewMode = PickerViewMode.thumbnail;
                    picker.suggestedStartLocation = PickerLocationId.picturesLibrary;
                    picker.fileTypeFilter.push(".jpg");
 
                    picker.pickSingleFileAsync().then(function (file) {
                        if (file != null) {
                            document.getElementById("myImg").src = URL.createObjectURL(file);
                        }
                    });
                }
            });
        }
    });
 
})();
JavaScriptWinRT.zip

汪鸣峰

unread,
May 15, 2012, 2:18:17 AM5/15/12
to js...@googlegroups.com
thnx. 还有个小问题,就是这两段代码是完全等价吗? Jscex异步同步化后,如果最后再添加删除文件的代码应该是在pickSingleFileAsync() 方法执行后再执行的。但如果没用Jscex,要达到同样效果的话代码只能添加在Promise对象的then或者done方法中, 如果是Promise.done方法的多层嵌套,我能否在每一个方法调用前都加上await从而保证最外一层和写在他之后的代码是同步的呢。(附件是我想在文件夹全部拷贝结束后再删除原文件夹的代码。)

2012/5/14 Jeffrey Zhao <je...@live.com>
Jscex-test.js

Jeffrey Zhao

unread,
May 15, 2012, 9:41:35 AM5/15/12
to js...@googlegroups.com
你这代码写的完全不对,$await和then什么不是不能混用,但也不是像你这样随意混用的。注意$await只能“直接”用在eval(Jscex.compile())的函数里,再套一个函数或是function什么的就不能用$await了,如果要用,那个function也需要eval(Jscex.compile())。
 
当然,eval(Jscex.compile())是可以嵌套的。

汪鸣峰

unread,
May 15, 2012, 10:43:12 AM5/15/12
to js...@googlegroups.com
老赵,谢谢!
Reply all
Reply to author
Forward
0 new messages