Merge pull request #6064 from jimfb/provide-msunsafe-wrapper

Create ms-unsafe functions in one place, simplifies code.
This commit is contained in:
Jim
2016-02-18 11:14:47 -08:00
4 changed files with 50 additions and 38 deletions
@@ -9,8 +9,6 @@
* @providesModule DOMChildrenOperations
*/
/* globals MSApp */
'use strict';
var DOMLazyTree = require('DOMLazyTree');
@@ -18,6 +16,7 @@ var Danger = require('Danger');
var ReactMultiChildUpdateTypes = require('ReactMultiChildUpdateTypes');
var ReactPerf = require('ReactPerf');
var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction');
var setInnerHTML = require('setInnerHTML');
var setTextContent = require('setTextContent');
@@ -33,19 +32,14 @@ function getNodeAfter(parentNode, node) {
* @param {number} index Index at which to insert the child.
* @internal
*/
function insertChildAt(parentNode, childNode, referenceNode) {
// We rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. (Using `undefined` is not allowed by all browsers so
// we are careful to use `null`.)
if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
MSApp.execUnsafeLocalFunction(function() {
parentNode.insertBefore(childNode, referenceNode);
});
} else {
var insertChildAt = createMicrosoftUnsafeLocalFunction(
function(parentNode, childNode, referenceNode) {
// We rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. (Using `undefined` is not allowed by all browsers so
// we are careful to use `null`.)
parentNode.insertBefore(childNode, referenceNode);
}
}
);
function insertLazyTreeChildAt(parentNode, childTree, referenceNode) {
DOMLazyTree.insertTreeBefore(parentNode, childTree, referenceNode);
+5 -11
View File
@@ -9,10 +9,9 @@
* @providesModule DOMLazyTree
*/
/* globals MSApp */
'use strict';
var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction');
var setTextContent = require('setTextContent');
/**
@@ -52,17 +51,12 @@ function insertTreeChildren(tree) {
}
}
function insertTreeBefore(parentNode, tree, referenceNode) {
if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
MSApp.execUnsafeLocalFunction(function() {
parentNode.insertBefore(tree.node, referenceNode);
});
} else {
var insertTreeBefore = createMicrosoftUnsafeLocalFunction(
function(parentNode, tree, referenceNode) {
parentNode.insertBefore(tree.node, referenceNode);
insertTreeChildren(tree);
}
insertTreeChildren(tree);
}
);
function replaceChildWithTree(oldNode, newTree) {
oldNode.parentNode.replaceChild(newTree.node, oldNode);
@@ -0,0 +1,31 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule createMicrosoftUnsafeLocalFunction
*/
/* globals MSApp */
'use strict';
/**
* Create a function which has 'unsafe' privileges (required by windows8 apps)
*/
var createMicrosoftUnsafeLocalFunction = function(func) {
if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
return function(arg0, arg1, arg2, arg3) {
MSApp.execUnsafeLocalFunction(function() {
return func(arg0, arg1, arg2, arg3);
});
};
} else {
return func;
}
};
module.exports = createMicrosoftUnsafeLocalFunction;
+7 -14
View File
@@ -9,8 +9,6 @@
* @providesModule setInnerHTML
*/
/* globals MSApp */
'use strict';
var ExecutionEnvironment = require('ExecutionEnvironment');
@@ -18,6 +16,8 @@ var ExecutionEnvironment = require('ExecutionEnvironment');
var WHITESPACE_TEST = /^[ \r\n\t\f]/;
var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
var createMicrosoftUnsafeLocalFunction = require('createMicrosoftUnsafeLocalFunction');
/**
* Set the innerHTML property of a node, ensuring that whitespace is preserved
* even in IE8.
@@ -26,18 +26,11 @@ var NONVISIBLE_TEST = /<(!--|link|noscript|meta|script|style)[ \r\n\t\f\/>]/;
* @param {string} html
* @internal
*/
var setInnerHTML = function(node, html) {
node.innerHTML = html;
};
// Win8 apps: Allow all html to be inserted
if (typeof MSApp !== 'undefined' && MSApp.execUnsafeLocalFunction) {
setInnerHTML = function(node, html) {
MSApp.execUnsafeLocalFunction(function() {
node.innerHTML = html;
});
};
}
var setInnerHTML = createMicrosoftUnsafeLocalFunction(
function(node, html) {
node.innerHTML = html;
}
);
if (ExecutionEnvironment.canUseDOM) {
// IE8: When updating a just created node with innerHTML only leading