@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
98 lines • 3.35 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 { ChildRelationBase } from "../relation";
import { RelationRole } from "../relation-role";
export class ChildToOneParentRelation extends ChildRelationBase {
get isDirty() {
if (!this.isTracking) {
return false;
}
else {
return this._dirtyValueCalculator.isDirty(this._parent);
}
}
get parent() {
return this._parent;
}
set parent(id) {
Guard.validIdOrNull(id);
this._parent = id;
}
constructor(name, properties = null, client, inheritsSecurity) {
super(name, properties, client, inheritsSecurity);
this._parent = null;
this.role = RelationRole.Child;
this.isMultiValue = false;
}
getIds() {
if (this._parent !== 0 && this._parent !== null) {
return [this._parent];
}
else {
return [];
}
}
setIds(ids) {
Guard.arrayMaxOne(ids);
if (ids.length > 0) {
Guard.validId(ids[0]);
this._parent = ids[0];
}
else {
this._parent = null;
}
}
clear() {
this._parent = null;
}
getId() {
return this._parent;
}
setId(id) {
Guard.validIdOrNull(id);
this._parent = id;
}
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);
});
}
startTracking() {
if (this.isTracking)
return;
this.isTracking = true;
this._dirtyValueCalculator = new DirtyValueCalculator();
this._dirtyValueCalculator.setOriginalValue(this._parent);
}
markClean() {
if (this.isTracking) {
this._dirtyValueCalculator.setOriginalValue(this._parent);
}
}
getParentProperties() {
if (this._parent == null) {
return {};
}
return this.properties[this._parent] == null ? {} : this.properties[this._parent];
}
}
//# sourceMappingURL=child-to-one-parent-relation.js.map