@sitecore/sc-contenthub-webclient-sdk
Version:
Sitecore Content Hub WebClient SDK.
105 lines • 4.24 kB
JavaScript
"use strict";
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ParentToManyChildrenRelation = void 0;
const dirty_value_calculator_1 = __importDefault(require("../../../dirty-value-calculator"));
const guard_1 = __importDefault(require("../../../guard"));
const entity_load_configuration_1 = require("../../querying/entity-load-configuration");
const relation_1 = require("../relation");
const relation_role_1 = require("../relation-role");
class ParentToManyChildrenRelation extends relation_1.RelationBase {
get isFullyLoaded() {
return this.childTotal == null || this._children.length === this.childTotal;
}
get isDirty() {
if (!this.isTracking) {
return false;
}
else {
return this._dirtyValueCalculator.isDirty(this._children);
}
}
get children() {
return this._children.slice();
}
constructor(name, properties = null, client, childTotal) {
super(name, properties, client);
this._children = [];
this.role = relation_role_1.RelationRole.Parent;
this.isMultiValue = true;
this.childTotal = childTotal;
}
getIds() {
return this._children.slice();
}
setIds(ids) {
guard_1.default.validIds(ids);
this._children.splice(0, this._children.length);
this._children.push(...ids);
}
clear() {
this._children.splice(0, this._children.length);
}
add(id) {
guard_1.default.validId(id);
if (!this._children.includes(id)) {
this._children.push(id);
}
}
addRange(ids) {
guard_1.default.validIds(ids);
ids.forEach(id => {
if (!this._children.includes(id)) {
this._children.push(id);
}
});
}
addAsync(identifier) {
return __awaiter(this, void 0, void 0, function* () {
guard_1.default.notNullOrUndefined(this.client);
guard_1.default.stringNotNullOrEmpty(identifier);
const entity = yield this.client.entities.getAsync(identifier, entity_load_configuration_1.EntityLoadConfiguration.Minimal);
if (entity && entity.id) {
this.add(entity.id);
}
});
}
addRangeAsync(identifiers) {
return __awaiter(this, void 0, void 0, function* () {
guard_1.default.notNullOrUndefined(this.client);
guard_1.default.arrayNoneNullOrEmptyString(identifiers);
const entities = yield this.client.entities.getManyAsync(identifiers, entity_load_configuration_1.EntityLoadConfiguration.Minimal);
if (entities) {
this.addRange(entities.filter(x => x.id !== null).map(x => x.id));
}
});
}
startTracking() {
if (this.isTracking)
return;
this.isTracking = true;
this._dirtyValueCalculator = new dirty_value_calculator_1.default();
this._dirtyValueCalculator.setOriginalValue(this._children);
}
markClean() {
if (this.isTracking) {
this._dirtyValueCalculator.setOriginalValue(this._children);
}
}
getChildProperties(id) {
return this.properties[id] == null ? {} : this.properties[id];
}
}
exports.ParentToManyChildrenRelation = ParentToManyChildrenRelation;
//# sourceMappingURL=parent-to-many-children-relation.js.map