Merge pull request #138 from devongovett/js-caching
Implement caching in the JS version
This commit is contained in:
@@ -63,7 +63,7 @@ var computeLayout = (function() {
|
|||||||
// properties. For the JavaScript version this function adds these properties
|
// properties. For the JavaScript version this function adds these properties
|
||||||
// if they don't already exist.
|
// if they don't already exist.
|
||||||
function fillNodes(node) {
|
function fillNodes(node) {
|
||||||
if (!node.layout) {
|
if (!node.layout || node.isDirty) {
|
||||||
node.layout = {
|
node.layout = {
|
||||||
width: undefined,
|
width: undefined,
|
||||||
height: undefined,
|
height: undefined,
|
||||||
@@ -439,7 +439,7 @@ var computeLayout = (function() {
|
|||||||
return -getPosition(node, trailing[axis]);
|
return -getPosition(node, trailing[axis]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function layoutNode(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
|
function layoutNodeImpl(node, parentMaxWidth, /*css_direction_t*/parentDirection) {
|
||||||
var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
|
var/*css_direction_t*/ direction = resolveDirection(node, parentDirection);
|
||||||
var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
|
var/*(c)!css_flex_direction_t*//*(java)!int*/ mainAxis = resolveAxis(getFlexDirection(node), direction);
|
||||||
var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
|
var/*(c)!css_flex_direction_t*//*(java)!int*/ crossAxis = getCrossFlexDirection(mainAxis, direction);
|
||||||
@@ -1123,7 +1123,52 @@ var computeLayout = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function layoutNode(node, parentMaxWidth, parentDirection) {
|
||||||
|
node.shouldUpdate = true;
|
||||||
|
|
||||||
|
var direction = node.style.direction || CSS_DIRECTION_LTR;
|
||||||
|
var skipLayout =
|
||||||
|
!node.isDirty &&
|
||||||
|
node.lastLayout &&
|
||||||
|
node.lastLayout.requestedHeight === node.layout.height &&
|
||||||
|
node.lastLayout.requestedWidth === node.layout.width &&
|
||||||
|
node.lastLayout.parentMaxWidth === parentMaxWidth &&
|
||||||
|
node.lastLayout.direction === direction;
|
||||||
|
|
||||||
|
if (skipLayout) {
|
||||||
|
node.layout.width = node.lastLayout.width;
|
||||||
|
node.layout.height = node.lastLayout.height;
|
||||||
|
node.layout.top = node.lastLayout.top;
|
||||||
|
node.layout.left = node.lastLayout.left;
|
||||||
|
} else {
|
||||||
|
if (!node.lastLayout) {
|
||||||
|
node.lastLayout = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
node.lastLayout.requestedWidth = node.layout.width;
|
||||||
|
node.lastLayout.requestedHeight = node.layout.height;
|
||||||
|
node.lastLayout.parentMaxWidth = parentMaxWidth;
|
||||||
|
node.lastLayout.direction = direction;
|
||||||
|
|
||||||
|
// Reset child layouts
|
||||||
|
node.children.forEach(function(child) {
|
||||||
|
child.layout.width = undefined;
|
||||||
|
child.layout.height = undefined;
|
||||||
|
child.layout.top = 0;
|
||||||
|
child.layout.left = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
layoutNodeImpl(node, parentMaxWidth, parentDirection);
|
||||||
|
|
||||||
|
node.lastLayout.width = node.layout.width;
|
||||||
|
node.lastLayout.height = node.layout.height;
|
||||||
|
node.lastLayout.top = node.layout.top;
|
||||||
|
node.lastLayout.left = node.layout.left;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
layoutNodeImpl: layoutNodeImpl,
|
||||||
computeLayout: layoutNode,
|
computeLayout: layoutNode,
|
||||||
fillNodes: fillNodes
|
fillNodes: fillNodes
|
||||||
};
|
};
|
||||||
|
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var layoutTestUtils = require('./Layout-test-utils.js');
|
var layoutTestUtils = require('./Layout-test-utils.js');
|
||||||
var computeLayout = require('./Layout.js').computeLayout;
|
var computeLayout = require('./Layout.js').layoutNodeImpl;
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var JavaTranspiler = require('./JavaTranspiler.js');
|
var JavaTranspiler = require('./JavaTranspiler.js');
|
||||||
var CSharpTranspiler = require('./CSharpTranspiler.js');
|
var CSharpTranspiler = require('./CSharpTranspiler.js');
|
||||||
|
Reference in New Issue
Block a user