incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [7/9] js commit: declare some obj to solve deep nesting
Date Wed, 17 Oct 2012 20:38:34 GMT
declare some obj to solve deep nesting

Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/6c511192
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/6c511192
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/6c511192

Branch: refs/heads/master
Commit: 6c5111922cff99062cb06605b98e0e7840ee8fa3
Parents: aa8d7ee
Author: wangmingfeng <mingfengwang01@gmail.com>
Authored: Thu Oct 11 16:44:47 2012 +0800
Committer: wangmingfeng <mingfengwang01@gmail.com>
Committed: Thu Oct 11 16:44:47 2012 +0800

----------------------------------------------------------------------
 lib/windows8/plugin/windows8/FileProxy.js |   94 ++++++++++++------------
 1 files changed, 46 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/6c511192/lib/windows8/plugin/windows8/FileProxy.js
----------------------------------------------------------------------
diff --git a/lib/windows8/plugin/windows8/FileProxy.js b/lib/windows8/plugin/windows8/FileProxy.js
index d860d6f..3b48036 100644
--- a/lib/windows8/plugin/windows8/FileProxy.js
+++ b/lib/windows8/plugin/windows8/FileProxy.js
@@ -526,6 +526,27 @@ module.exports = {
                 Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(
                     function (sFolder) {
                         copyFiles = function (srcPath, parentPath) {
+                            var coreCopy = function (storageFolderTop, complete) {
+                                storageFolderTop.createFolderQuery().getFoldersAsync().then(function
(folderList) {
+                                    var folderPromiseArr = [];
+                                    if (folderList.length === 0) { complete(); }
+                                    else {
+                                        Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function
(storageFolderTarget) {
+                                            var tempPromiseArr = [];
+                                            var index = 0;
+                                            for (var j = 0; j < folderList.length; j++)
{
+                                                tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function
(targetFolder) {
+                                                    folderPromiseArr.push(copyFiles(folderList[j].path,
targetFolder.path));
+                                                });
+                                            }
+                                            WinJS.Promise.join(tempPromiseArr).then(function
() {
+                                                WinJS.Promise.join(folderPromiseArr).then(complete);
+                                            });
+                                        });
+                                    }
+                                });
+                            };
+
                             return new WinJS.Promise(function (complete) {
                                 var storageFolderTop = null;
                                 var filePromiseArr = [];
@@ -542,30 +563,8 @@ module.exports = {
                                     for (var i = 0; i < fileListTop.length; i++) {
                                         filePromiseArr.push(fileListTop[i].copyAsync(targetStorageFolder));
                                     }
-
-                                    var coreCopy = function () {
-                                        storageFolderTop.createFolderQuery().getFoldersAsync().then(function
(folderList) {
-                                            var folderPromiseArr = [];
-                                            if (folderList.length === 0) { complete(); }
-                                            else {
-                                                Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function
(storageFolderTarget) {
-                                                    var tempPromiseArr = [];
-                                                    var index = 0;
-                                                    for (var j = 0; j < folderList.length;
j++) {
-                                                        tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function
(targetFolder) {
-                                                            folderPromiseArr.push(copyFiles(folderList[j].path,
targetFolder.path));
-                                                        });
-                                                    }
-                                                    WinJS.Promise.join(tempPromiseArr).then(function
() {
-                                                        WinJS.Promise.join(folderPromiseArr).then(complete);
-                                                    });
-                                                });
-                                            }
-                                        });
-                                    }
-
                                     WinJS.Promise.join(filePromiseArr).then(function () {
-                                        coreCopy();
+                                        coreCopy(storageFolderTop, complete);
                                     });
                                 });
                             });
@@ -649,6 +648,29 @@ module.exports = {
                 Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(
                     function (sFolder) {
                         moveFiles = function (srcPath, parentPath) {
+                            var coreMove = function (storageFolderTop, complete) {
+                                storageFolderTop.createFolderQuery().getFoldersAsync().then(function
(folderList) {
+                                    var folderPromiseArr = [];
+                                    if (folderList.length === 0) {
+                                        // If failed, we must cancel the deletion of folders
& files.So here wo can't delete the folder.
+                                        complete();
+                                    }
+                                    else {
+                                        Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function
(storageFolderTarget) {
+                                            var tempPromiseArr = [];
+                                            var index = 0;
+                                            for (var j = 0; j < folderList.length; j++)
{
+                                                tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function
(targetFolder) {
+                                                    folderPromiseArr.push(moveFiles(folderList[j].path,
targetFolder.path));
+                                                });
+                                            }
+                                            WinJS.Promise.join(tempPromiseArr).then(function
() {
+                                                WinJS.Promise.join(folderPromiseArr).then(complete);
+                                            });
+                                        });
+                                    }
+                                });
+                            };
                             return new WinJS.Promise(function (complete) {
                                 var storageFolderTop = null;
                                 Windows.Storage.StorageFolder.getFolderFromPathAsync(srcPath).then(function
(storageFolder) {
@@ -662,32 +684,8 @@ module.exports = {
                                                 filePromiseArr.push(fileList[i].moveAsync(dstStorageFolder));
                                             }
                                         }
-                                        var coreMove = function () {
-                                            storageFolderTop.createFolderQuery().getFoldersAsync().then(function
(folderList) {
-                                                var folderPromiseArr = [];
-                                                if (folderList.length === 0) {
-                                                    // If failed, we must cancel the deletion
of folders & files.So here wo can't delete the folder.
-                                                    complete();
-                                                }
-                                                else {
-                                                    Windows.Storage.StorageFolder.getFolderFromPathAsync(parentPath).then(function
(storageFolderTarget) {
-                                                        var tempPromiseArr = [];
-                                                        var index = 0;
-                                                        for (var j = 0; j < folderList.length;
j++) {
-                                                            tempPromiseArr[index++] = storageFolderTarget.createFolderAsync(folderList[j].name).then(function
(targetFolder) {
-                                                                folderPromiseArr.push(moveFiles(folderList[j].path,
targetFolder.path));
-                                                            });
-                                                        }
-                                                        WinJS.Promise.join(tempPromiseArr).then(function
() {
-                                                            WinJS.Promise.join(folderPromiseArr).then(complete);
-                                                        });
-                                                    });
-                                                }
-                                            });
-                                        }
-
                                         WinJS.Promise.join(filePromiseArr).then(function
() {
-                                            coreMove();
+                                            coreMove(storageFolderTop, complete);
                                         }, function () { });
                                     });
                                 });


Mime
View raw message