@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
98 lines • 3.28 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import DirtyValueCalculator from "../../../dirty-value-calculator";
import Guard from "../../../guard";
import { EntityLoadConfiguration } from "../../querying/entity-load-configuration";
import { RelationBase } from "../relation";
import { RelationRole } from "../relation-role";
export class ParentToOneChildRelation extends RelationBase {
get child() {
return this._child;
}
set child(id) {
Guard.validIdOrNull(id);
this._child = id;
}
get isDirty() {
if (!this.isTracking) {
return false;
}
else {
return this._dirtyValueCalculator.isDirty(this._child);
}
}
constructor(name, properties = null, client) {
super(name, properties, client);
this._child = null;
this.role = RelationRole.Parent;
this.isMultiValue = false;
}
getIds() {
if (this._child !== 0 && this._child !== null) {
return [this._child];
}
else {
return [];
}
}
setIds(ids) {
Guard.arrayMaxOne(ids);
if (ids.length > 0) {
Guard.validId(ids[0]);
this._child = ids[0];
}
else {
this._child = null;
}
}
setIdentifierAsync(identifier) {
return __awaiter(this, void 0, void 0, function* () {
Guard.notNullOrUndefined(this.client);
Guard.stringNotNullOrEmpty(identifier);
if (identifier) {
const entity = yield this.client.entities.getAsync(identifier, EntityLoadConfiguration.Minimal);
if (entity && entity.id) {
this.setId(entity.id);
return;
}
}
this.setId(null);
});
}
clear() {
this._child = null;
}
getId() {
return this._child;
}
setId(id) {
Guard.validIdOrNull(id);
this._child = id;
}
startTracking() {
if (this.isTracking)
return;
this.isTracking = true;
this._dirtyValueCalculator = new DirtyValueCalculator();
this._dirtyValueCalculator.setOriginalValue(this._child);
}
markClean() {
if (this.isTracking) {
this._dirtyValueCalculator.setOriginalValue(this._child);
}
}
getChildProperties() {
if (this._child == null) {
return {};
}
return this.properties[this._child] == null ? {} : this.properties[this._child];
}
}
//# sourceMappingURL=parent-to-one-child-relation.js.map