Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace defaultValue with ?? #12207

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 26 additions & 54 deletions packages/engine/Source/DataSources/BillboardGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ function BillboardGraphics(options) {
this._disableDepthTestDistanceSubscription = undefined;
this._splitDirection = undefined;
this._splitDirectionSubscription = undefined;

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
this.merge(options ?? defaultValue.EMPTY_OBJECT);
}

Object.defineProperties(BillboardGraphics.prototype, {
Expand Down Expand Up @@ -389,57 +388,30 @@ BillboardGraphics.prototype.merge = function (source) {
throw new DeveloperError("source is required.");
}
//>>includeEnd('debug');

this.show = defaultValue(this._show, source.show);
this.image = defaultValue(this._image, source.image);
this.scale = defaultValue(this._scale, source.scale);
this.pixelOffset = defaultValue(this._pixelOffset, source.pixelOffset);
this.eyeOffset = defaultValue(this._eyeOffset, source.eyeOffset);
this.horizontalOrigin = defaultValue(
this._horizontalOrigin,
source.horizontalOrigin,
);
this.verticalOrigin = defaultValue(
this._verticalOrigin,
source.verticalOrigin,
);
this.heightReference = defaultValue(
this._heightReference,
source.heightReference,
);
this.color = defaultValue(this._color, source.color);
this.rotation = defaultValue(this._rotation, source.rotation);
this.alignedAxis = defaultValue(this._alignedAxis, source.alignedAxis);
this.sizeInMeters = defaultValue(this._sizeInMeters, source.sizeInMeters);
this.width = defaultValue(this._width, source.width);
this.height = defaultValue(this._height, source.height);
this.scaleByDistance = defaultValue(
this._scaleByDistance,
source.scaleByDistance,
);
this.translucencyByDistance = defaultValue(
this._translucencyByDistance,
source.translucencyByDistance,
);
this.pixelOffsetScaleByDistance = defaultValue(
this._pixelOffsetScaleByDistance,
source.pixelOffsetScaleByDistance,
);
this.imageSubRegion = defaultValue(
this._imageSubRegion,
source.imageSubRegion,
);
this.distanceDisplayCondition = defaultValue(
this._distanceDisplayCondition,
source.distanceDisplayCondition,
);
this.disableDepthTestDistance = defaultValue(
this._disableDepthTestDistance,
source.disableDepthTestDistance,
);
this.splitDirection = defaultValue(
this.splitDirection,
source.splitDirection,
);
this.show = this._show ?? source.show;
this.image = this._image ?? source.image;
this.scale = this._scale ?? source.scale;
this.pixelOffset = this._pixelOffset ?? source.pixelOffset;
this.eyeOffset = this._eyeOffset ?? source.eyeOffset;
this.horizontalOrigin = this._horizontalOrigin ?? source.horizontalOrigin;
this.verticalOrigin = this._verticalOrigin ?? source.verticalOrigin;
this.heightReference = this._heightReference ?? source.heightReference;
this.color = this._color ?? source.color;
this.rotation = this._rotation ?? source.rotation;
this.alignedAxis = this._alignedAxis ?? source.alignedAxis;
this.sizeInMeters = this._sizeInMeters ?? source.sizeInMeters;
this.width = this._width ?? source.width;
this.height = this._height ?? source.height;
this.scaleByDistance = this._scaleByDistance ?? source.scaleByDistance;
this.translucencyByDistance =
this._translucencyByDistance ?? source.translucencyByDistance;
this.pixelOffsetScaleByDistance =
this._pixelOffsetScaleByDistance ?? source.pixelOffsetScaleByDistance;
this.imageSubRegion = this._imageSubRegion ?? source.imageSubRegion;
this.distanceDisplayCondition =
this._distanceDisplayCondition ?? source.distanceDisplayCondition;
this.disableDepthTestDistance =
this._disableDepthTestDistance ?? source.disableDepthTestDistance;
this.splitDirection = this.splitDirection ?? source.splitDirection;
};
export default BillboardGraphics;
2 changes: 1 addition & 1 deletion packages/engine/Source/DataSources/BoxGraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function BoxGraphics(options) {
this._distanceDisplayCondition = undefined;
this._distanceDisplayConditionSubscription = undefined;

this.merge(defaultValue(options, defaultValue.EMPTY_OBJECT));
this.merge(options ?? defaultValue.EMPTY_OBJECT);
}

Object.defineProperties(BoxGraphics.prototype, {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Cartesian3 from "../Core/Cartesian3.js";
import defaultValue from "../Core/defaultValue.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Event from "../Core/Event.js";
Expand All @@ -20,7 +19,7 @@ import PositionProperty from "./PositionProperty.js";
function ConstantPositionProperty(value, referenceFrame) {
this._definitionChanged = new Event();
this._value = Cartesian3.clone(value);
this._referenceFrame = defaultValue(referenceFrame, ReferenceFrame.FIXED);
this._referenceFrame = referenceFrame ?? ReferenceFrame.FIXED;
}

Object.defineProperties(ConstantPositionProperty.prototype, {
Expand Down
10 changes: 4 additions & 6 deletions packages/engine/Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ function loadXmlFromZip(entry, uriResolver) {
}

function loadDataUriFromZip(entry, uriResolver) {
const mimeType = defaultValue(
MimeTypes.detectFromFilename(entry.filename),
"application/octet-stream",
);
const mimeType =
MimeTypes.detectFromFilename(entry.filename) ?? "application/octet-stream";
return Promise.resolve(entry.getData(new zip.Data64URIWriter(mimeType))).then(
function (dataUri) {
uriResolver[entry.filename] = dataUri;
Expand Down Expand Up @@ -851,8 +849,8 @@ function getIconHref(
const palette = href.charAt(21);

// Get the icon number
let x = defaultValue(queryNumericValue(iconNode, "x", namespaces.gx), 0);
let y = defaultValue(queryNumericValue(iconNode, "y", namespaces.gx), 0);
let x = queryNumericValue(iconNode, "x", namespaces.gx) ?? 0;
let y = queryNumericValue(iconNode, "y", namespaces.gx) ?? 0;
x = Math.min(x / 32, 7);
y = 7 - Math.min(y / 32, 7);
const iconNum = 8 * y + x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,11 @@ import createCommand from "../createCommand.js";
* @exception {DeveloperError} terrainProviderViewModels must be an array.
*/
function BaseLayerPickerViewModel(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);
options = options ?? defaultValue.EMPTY_OBJECT;

const globe = options.globe;
const imageryProviderViewModels = defaultValue(
options.imageryProviderViewModels,
[],
);
const terrainProviderViewModels = defaultValue(
options.terrainProviderViewModels,
[],
);
const imageryProviderViewModels = options.imageryProviderViewModels ?? [];
const terrainProviderViewModels = options.terrainProviderViewModels ?? [];

//>>includeStart('debug', pragmas.debug);
if (!defined(globe)) {
Expand Down Expand Up @@ -301,11 +295,8 @@ function BaseLayerPickerViewModel(options) {
this._toggleDropDown = createCommand(function () {
that.dropDownVisible = !that.dropDownVisible;
});

this.selectedImagery = defaultValue(
options.selectedImageryProviderViewModel,
imageryProviderViewModels[0],
);
this.selectedImagery =
options.selectedImageryProviderViewModel ?? imageryProviderViewModels[0];
this.selectedTerrain = options.selectedTerrainProviderViewModel;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/widgets/Source/BaseLayerPicker/ProviderViewModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaultValue, defined, DeveloperError } from "@cesium/engine";
import { defined, DeveloperError } from "@cesium/engine";
import knockout from "../ThirdParty/knockout.js";
import createCommand from "../createCommand.js";

Expand Down Expand Up @@ -61,7 +61,7 @@ function ProviderViewModel(options) {
*/
this.iconUrl = options.iconUrl;

this._category = defaultValue(options.category, "");
this._category = options.category ?? "";

knockout.track(this, ["name", "tooltip", "iconUrl"]);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
defaultValue,
defined,
destroyObject,
DeveloperError,
Expand Down Expand Up @@ -82,10 +81,7 @@ function FullscreenButtonViewModel(fullscreenElement, container) {
knockout.getObservable(this, "isFullscreenEnabled"),
);

this._fullscreenElement = defaultValue(
getElement(fullscreenElement),
ownerDocument.body,
);
this._fullscreenElement = getElement(fullscreenElement) ?? ownerDocument.body;

this._callback = function () {
tmpIsFullscreen(Fullscreen.fullscreen);
Expand Down
11 changes: 4 additions & 7 deletions packages/widgets/Source/Geocoder/GeocoderViewModel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
computeFlyToLocationForRectangle,
defaultValue,
defined,
DeveloperError,
destroyObject,
Expand Down Expand Up @@ -71,7 +70,7 @@ function GeocoderViewModel(options) {
});

this._searchCommand = createCommand(function (geocodeType) {
geocodeType = defaultValue(geocodeType, GeocodeType.SEARCH);
geocodeType = geocodeType ?? GeocodeType.SEARCH;
that._focusTextbox = false;
if (defined(that._selectedSuggestion)) {
that.activateSuggestion(that._selectedSuggestion);
Expand Down Expand Up @@ -153,16 +152,14 @@ function GeocoderViewModel(options) {
* @type {boolean}
* @default true
*/
this.autoComplete = defaultValue(options.autocomplete, true);
this.autoComplete = options.autocomplete ?? true;

/**
* Gets and sets the command called when a geocode destination is found
* @type {Geocoder.DestinationFoundFunction}
*/
this.destinationFound = defaultValue(
options.destinationFound,
GeocoderViewModel.flyToDestination,
);
this.destinationFound =
options.destinationFound ?? GeocoderViewModel.flyToDestination;

this._focusTextbox = false;

Expand Down
6 changes: 3 additions & 3 deletions packages/widgets/Source/InspectorShared.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Check, defaultValue, defined } from "@cesium/engine";
import { Check, defined } from "@cesium/engine";

/**
* A static class with helper functions used by CesiumInspector, Cesium3DTilesInspector, and VoxelInspector
Expand Down Expand Up @@ -109,7 +109,7 @@ InspectorShared.createRangeInput = function (
Check.typeOf.number("max", max);
//>>includeEnd('debug');

inputValueBinding = defaultValue(inputValueBinding, sliderValueBinding);
inputValueBinding = inputValueBinding ?? sliderValueBinding;
const input = document.createElement("input");
input.setAttribute("data-bind", `value: ${inputValueBinding}`);
input.type = "number";
Expand All @@ -118,7 +118,7 @@ InspectorShared.createRangeInput = function (
slider.type = "range";
slider.min = min;
slider.max = max;
slider.step = defaultValue(step, "any");
slider.step = step ?? "any";
slider.setAttribute(
"data-bind",
`valueUpdate: "input", value: ${sliderValueBinding}`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
buildModuleUrl,
defaultValue,
defined,
destroyObject,
DeveloperError,
Expand Down Expand Up @@ -42,11 +41,7 @@ function NavigationHelpButton(options) {

const viewModel = new NavigationHelpButtonViewModel();

const showInsructionsDefault = defaultValue(
options.instructionsInitiallyVisible,
false,
);
viewModel.showInstructions = showInsructionsDefault;
viewModel.showInstructions = options.instructionsInitiallyVisible ?? false;

viewModel._svgPath =
"M16,1.466C7.973,1.466,1.466,7.973,1.466,16c0,8.027,6.507,14.534,14.534,14.534c8.027,0,14.534-6.507,14.534-14.534C30.534,7.973,24.027,1.466,16,1.466z M17.328,24.371h-2.707v-2.596h2.707V24.371zM17.328,19.003v0.858h-2.707v-1.057c0-3.19,3.63-3.696,3.63-5.963c0-1.034-0.924-1.826-2.134-1.826c-1.254,0-2.354,0.924-2.354,0.924l-1.541-1.915c0,0,1.519-1.584,4.137-1.584c2.487,0,4.796,1.54,4.796,4.136C21.156,16.208,17.328,16.627,17.328,19.003z";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
defaultValue,
defined,
destroyObject,
DeveloperError,
Expand Down Expand Up @@ -33,10 +32,11 @@ function PerformanceWatchdogViewModel(options) {
* Gets or sets the message to display when a low frame rate is detected. This string will be interpreted as HTML.
* @type {string}
*/
this.lowFrameRateMessage = defaultValue(
options.lowFrameRateMessage,
"This application appears to be performing poorly on your system. Please try using a different web browser or updating your video drivers.",
);

this.lowFrameRateMessage =
options.lowFrameRateMessage ??
"This application appears to be performing poorly on your system. " +
"Please try using a different web browser or updating your video drivers.";

/**
* Gets or sets a value indicating whether the low frame rate message has previously been dismissed by the user. If it has
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
defaultValue,
defined,
destroyObject,
DeveloperError,
Expand Down Expand Up @@ -36,7 +35,7 @@ function SceneModePickerViewModel(scene, duration) {
this._eventHelper = new EventHelper();
this._eventHelper.add(scene.morphStart, morphStart);

this._duration = defaultValue(duration, 2.0);
this._duration = duration ?? 2.0;

/**
* Gets or sets the current SceneMode. This property is observable.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Cartesian2,
defaultValue,
defined,
DeveloperError,
EasingFunction,
Expand Down Expand Up @@ -43,7 +42,7 @@ function SelectionIndicatorViewModel(
this._screenPositionX = offScreen;
this._screenPositionY = offScreen;
this._tweens = scene.tweens;
this._container = defaultValue(container, document.body);
this._container = container ?? document.body;
this._selectionIndicatorElement = selectionIndicatorElement;
this._scale = 1;

Expand Down
4 changes: 2 additions & 2 deletions packages/widgets/Source/Timeline/TimelineHighlightRange.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { defaultValue, JulianDate } from "@cesium/engine";
import { JulianDate } from "@cesium/engine";

/**
* @private
*/
function TimelineHighlightRange(color, heightInPx, base) {
this._color = color;
this._height = heightInPx;
this._base = defaultValue(base, 0);
this._base = base ?? 0;
}

TimelineHighlightRange.prototype.getHeight = function () {
Expand Down
6 changes: 3 additions & 3 deletions packages/widgets/Source/ToggleButtonViewModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ function ToggleButtonViewModel(command, options) {

this._command = command;

options = defaultValue(options, defaultValue.EMPTY_OBJECT);
options = options ?? defaultValue.EMPTY_OBJECT;

/**
* Gets or sets whether the button is currently toggled. This property is observable.
* @type {boolean}
* @default false
*/
this.toggled = defaultValue(options.toggled, false);
this.toggled = options.toggled ?? false;

/**
* Gets or sets the button's tooltip. This property is observable.
* @type {string}
* @default ''
*/
this.tooltip = defaultValue(options.tooltip, "");
this.tooltip = options.tooltip ?? "";

knockout.track(this, ["toggled", "tooltip"]);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/widgets/Source/VRButton/VRButtonViewModel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
defaultValue,
defined,
destroyObject,
DeveloperError,
Expand Down Expand Up @@ -156,7 +155,7 @@ function VRButtonViewModel(scene, vrElement) {
knockout.getObservable(this, "isVREnabled"),
);

this._vrElement = defaultValue(getElement(vrElement), document.body);
this._vrElement = getElement(vrElement) ?? document.body;

this._callback = function () {
if (!Fullscreen.fullscreen && isVRMode()) {
Expand Down
Loading
Loading