Skip to content

Commit

Permalink
Stricter typing of the setProperties data
Browse files Browse the repository at this point in the history
  • Loading branch information
Friedrich W. H. Kossebau committed Sep 18, 2014
1 parent 8ee8e1a commit f42f6de
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions webodf/lib/ops/OpAddStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ops.OpAddStyle = function OpAddStyle() {

var memberid, timestamp,
styleName, styleFamily, isAutomaticStyle,
/**@type{Object}*/setProperties,
/**@type{!odf.Formatting.StyleData}*/setProperties,
/** @const */stylens = odf.Namespaces.stylens;

/**
Expand Down Expand Up @@ -110,7 +110,7 @@ ops.OpAddStyle = function OpAddStyle() {
styleName:string,
styleFamily:string,
isAutomaticStyle:boolean,
setProperties:Object
setProperties:odf.Formatting.StyleData
}}*/
ops.OpAddStyle.Spec;
/**@typedef{{
Expand All @@ -119,6 +119,6 @@ ops.OpAddStyle.Spec;
styleName:string,
styleFamily:string,
isAutomaticStyle:(boolean|string),
setProperties:Object
setProperties:odf.Formatting.StyleData
}}*/
ops.OpAddStyle.InitSpec;
5 changes: 3 additions & 2 deletions webodf/lib/ops/OpApplyDirectStyling.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() {
position,
/**@type {number}*/
length,
/**@type{!odf.Formatting.StyleData}*/
setProperties,
odfUtils = odf.OdfUtils,
domUtils = core.DomUtils;
Expand Down Expand Up @@ -123,14 +124,14 @@ ops.OpApplyDirectStyling = function OpApplyDirectStyling() {
timestamp:number,
position:number,
length:number,
setProperties:!Object
setProperties:!odf.Formatting.StyleData
}}*/
ops.OpApplyDirectStyling.Spec;
/**@typedef{{
memberid:string,
timestamp:(number|undefined),
position:number,
length:number,
setProperties:!Object
setProperties:!odf.Formatting.StyleData
}}*/
ops.OpApplyDirectStyling.InitSpec;
5 changes: 3 additions & 2 deletions webodf/lib/ops/OpUpdateParagraphStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ops.OpUpdateParagraphStyle = function OpUpdateParagraphStyle() {
"use strict";

var memberid, timestamp, styleName,
/**@type{!odf.Formatting.StyleData}*/
setProperties,
/**@type{{attributes:string}}*/
removedProperties,
Expand Down Expand Up @@ -147,15 +148,15 @@ ops.OpUpdateParagraphStyle = function OpUpdateParagraphStyle() {
memberid:string,
timestamp:number,
styleName:string,
setProperties:Object,
setProperties:!odf.Formatting.StyleData,
removedProperties:{attributes:string}
}}*/
ops.OpUpdateParagraphStyle.Spec;
/**@typedef{{
memberid:string,
timestamp:(number|undefined),
styleName:string,
setProperties:Object,
setProperties:!odf.Formatting.StyleData,
removedProperties:{attributes:string}
}}*/
ops.OpUpdateParagraphStyle.InitSpec;
26 changes: 14 additions & 12 deletions webodf/lib/ops/OperationTransformMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ ops.OperationTransformMatrix = function OperationTransformMatrix() {

/**
* Returns a list with all attributes in setProperties that refer to styleName
* @param {Object} setProperties
* @param {string} styleName
* @param {?odf.Formatting.StyleData} setProperties
* @param {!string} styleName
* @return {!Array.<!string>}
*/
function getStyleReferencingAttributes(setProperties, styleName) {
Expand All @@ -80,8 +80,9 @@ ops.OperationTransformMatrix = function OperationTransformMatrix() {
return attributes;
}
/**
* @param {Object} setProperties
* @param {string} deletedStyleName
* @param {?odf.Formatting.StyleData} setProperties
* @param {!string} deletedStyleName
* @return {undefined}
*/
function dropStyleReferencingAttributes(setProperties, deletedStyleName) {
/**
Expand Down Expand Up @@ -194,7 +195,7 @@ ops.OperationTransformMatrix = function OperationTransformMatrix() {

/**
* Estimates if there are any properties set in the given properties object.
* @param {!Object} properties
* @param {!odf.Formatting.StyleData} properties
* @return {!boolean}
*/
function hasProperties(properties) {
Expand Down Expand Up @@ -230,20 +231,21 @@ ops.OperationTransformMatrix = function OperationTransformMatrix() {
}

/**
* @param {Object.<string,Object.<string,*>>} minorSet
* @param {Object.<string,{attributes:string}>} minorRem
* @param {Object.<string,Object.<string,*>>} majorSet
* @param {Object.<string,{attributes:string}>} majorRem
* @param {string} propertiesName
* @param {?odf.Formatting.StyleData} minorSet
* @param {?Object.<string,{attributes:string}>} minorRem
* @param {?odf.Formatting.StyleData} majorSet
* @param {?Object.<string,{attributes:string}>} majorRem
* @param {!string} propertiesName
* @return {?{majorChanged:boolean,minorChanged:boolean}}
*/
function dropOverruledAndUnneededProperties(minorSet, minorRem, majorSet, majorRem, propertiesName) {
var minorSP = minorSet ? minorSet[propertiesName] : null,
var minorSP = /**@type{?odf.Formatting.StyleData}*/(minorSet ? minorSet[propertiesName] : null),
minorRP = minorRem ? minorRem[propertiesName] : null,
majorSP = majorSet ? majorSet[propertiesName] : null,
majorSP = /**@type{?odf.Formatting.StyleData}*/(majorSet ? majorSet[propertiesName] : null),
majorRP = majorRem ? majorRem[propertiesName] : null,
result;

// TODO: also care for nested properties, like there can be e.g. with text:paragraph-properties
result = dropOverruledAndUnneededAttributes(minorSP, minorRP, majorSP, majorRP);

// remove empty setProperties
Expand Down

0 comments on commit f42f6de

Please sign in to comment.