Skip to content

Commit

Permalink
#54: Make codebase null safe (part 1). This doesn't cover all the cha…
Browse files Browse the repository at this point in the history
…nges and strictNullChecks is false here so that we can check in these changes incrementally while Travis will build as before.
  • Loading branch information
jumpinjackie committed Sep 27, 2016
1 parent 9de3835 commit 136397b
Show file tree
Hide file tree
Showing 24 changed files with 532 additions and 411 deletions.
7 changes: 4 additions & 3 deletions src/actions/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
isSearchCommand,
UIItem
} from "../api/contracts/weblayout";
import { IView } from "../api/contracts/common";
import { RuntimeMap } from "../api/contracts/runtime-map";
import * as logger from "../utils/logger";
import queryString = require("query-string");
const parse = require("url-parse");
const assign = require("object-assign");

function convertUIItems(items: UIItem[], cmdsByKey: any, noToolbarLabels = true, canSupportFlyouts = true): any[] {
return items.map(item => {
function convertUIItems(items: UIItem[] | null | undefined, cmdsByKey: any, noToolbarLabels = true, canSupportFlyouts = true): any[] {
return (items || []).map(item => {
if (isCommandItem(item)) {
const cmdDef: CommandDef = cmdsByKey[item.Command];
if (!cmdDef) {
Expand Down Expand Up @@ -126,7 +127,7 @@ export function initLayout(options) {
if (webLayout.PointSelectionBuffer != null) {
config.pointSelectionBuffer = webLayout.PointSelectionBuffer;
}
let initialView = null;
let initialView: IView | null = null;
if (webLayout.Map.InitialView != null) {
initialView = {
x: webLayout.Map.InitialView.CenterX,
Expand Down
38 changes: 21 additions & 17 deletions src/actions/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function combineSelectedFeatures(oldRes: SelectedFeature[], newRes: SelectedFeat
return merged;
}

function combineSelectedFeatureSets(oldRes: SelectedFeatureSet, newRes: SelectedFeatureSet): SelectedFeatureSet {
function combineSelectedFeatureSets(oldRes: SelectedFeatureSet | null | undefined, newRes: SelectedFeatureSet | null | undefined): SelectedFeatureSet | null | undefined {
if (oldRes == null) {
return newRes;
}
Expand All @@ -55,20 +55,22 @@ function combineSelectedFeatureSets(oldRes: SelectedFeatureSet, newRes: Selected
for (const layer of oldRes.SelectedLayer) {
merged.SelectedLayer.push(layer);
}
for (const layer of newRes.SelectedLayer) {
const layerId = layer["@id"];
const layerName = layer["@name"];
const existing = merged.SelectedLayer.filter(l => l["@id"] == layerId && l["@name"] == layerName);
if (existing.length == 0) {
merged.SelectedLayer.push(layer);
} else {
existing[0].Feature = combineSelectedFeatures(existing[0].Feature, layer.Feature);
if (newRes) {
for (const layer of newRes.SelectedLayer) {
const layerId = layer["@id"];
const layerName = layer["@name"];
const existing = merged.SelectedLayer.filter(l => l["@id"] == layerId && l["@name"] == layerName);
if (existing.length == 0) {
merged.SelectedLayer.push(layer);
} else {
existing[0].Feature = combineSelectedFeatures(existing[0].Feature, layer.Feature);
}
}
}
return merged;
}

function combineFeatureSets(oldRes: FeatureSet, newRes: FeatureSet): FeatureSet {
function combineFeatureSets(oldRes: FeatureSet | null | undefined, newRes: FeatureSet | null | undefined): FeatureSet | null | undefined {
if (oldRes == null) {
return newRes;
}
Expand All @@ -78,13 +80,15 @@ function combineFeatureSets(oldRes: FeatureSet, newRes: FeatureSet): FeatureSet
for (const layer of oldRes.Layer) {
merged.Layer.push(layer);
}
for (const layer of newRes.Layer) {
const layerId = layer["@id"];
const existing = merged.Layer.filter(l => l["@id"] == layerId);
if (existing.length == 0) {
merged.Layer.push(layer);
} else {
existing[0].Class.ID = uniq(existing[0].Class.ID.concat(layer.Class.ID));
if (newRes) {
for (const layer of newRes.Layer) {
const layerId = layer["@id"];
const existing = merged.Layer.filter(l => l["@id"] == layerId);
if (existing.length == 0) {
merged.Layer.push(layer);
} else {
existing[0].Class.ID = uniq(existing[0].Class.ID.concat(layer.Class.ID));
}
}
}
return merged;
Expand Down
2 changes: 0 additions & 2 deletions src/actions/taskpane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export function pushUrl(url: string, silent?: boolean) {
}

export function ensureParameters(url: string, mapName: string, session: string, locale?: string, uppercase = true): string {
if (url == null)
return null;
//If this is a component URL, let it be
if (url.indexOf("component://") >= 0) {
return url;
Expand Down
Loading

0 comments on commit 136397b

Please sign in to comment.