add js docs to template store

This commit is contained in:
Mads Rasmussen
2023-02-01 21:29:38 +01:00
parent 9409a2223f
commit 065dcc3489
2 changed files with 53 additions and 0 deletions

View File

@@ -13,14 +13,30 @@ import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbTemplateTreeStore extends UmbStoreBase {
#data = new ArrayState<EntityTreeItem>([], (x) => x.key);
/**
* Creates an instance of UmbTemplateTreeStore.
* @param {UmbControllerHostInterface} host
* @memberof UmbTemplateTreeStore
*/
constructor(host: UmbControllerHostInterface) {
super(host, UMB_TEMPLATE_TREE_STORE_CONTEXT_TOKEN.toString());
}
/**
* Appends items to the store
* @param {Array<EntityTreeItem>} items
* @memberof UmbTemplateTreeStore
*/
appendItems(items: Array<EntityTreeItem>) {
this.#data.append(items);
}
/**
* Updates an item in the store
* @param {string} key
* @param {Partial<EntityTreeItem>} data
* @memberof UmbTemplateTreeStore
*/
updateItem(key: string, data: Partial<EntityTreeItem>) {
const entries = this.#data.getValue();
const entry = entries.find((entry) => entry.key === key);
@@ -30,6 +46,11 @@ export class UmbTemplateTreeStore extends UmbStoreBase {
}
}
/**
* Removes an item from the store
* @param {string} key
* @memberof UmbTemplateTreeStore
*/
removeItem(key: string) {
const entries = this.#data.getValue();
const entry = entries.find((entry) => entry.key === key);
@@ -39,14 +60,31 @@ export class UmbTemplateTreeStore extends UmbStoreBase {
}
}
/**
* Returns an observable to observe the root items
* @return {*}
* @memberof UmbTemplateTreeStore
*/
rootItems() {
return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === null));
}
/**
* Returns an observable to observe the children of a given parent
* @param {(string | null)} parentKey
* @return {*}
* @memberof UmbTemplateTreeStore
*/
childrenOf(parentKey: string | null) {
return this.#data.getObservablePart((items) => items.filter((item) => item.parentKey === parentKey));
}
/**
* Returns an observable to observe the items with the given keys
* @param {Array<string>} keys
* @return {*}
* @memberof UmbTemplateTreeStore
*/
items(keys: Array<string>) {
return this.#data.getObservablePart((items) => items.filter((item) => keys.includes(item.key ?? '')));
}

View File

@@ -13,14 +13,29 @@ import { UmbControllerHostInterface } from '@umbraco-cms/controller';
export class UmbTemplateDetailStore extends UmbStoreBase {
#data = new ArrayState<Template>([], (x) => x.key);
/**
* Creates an instance of UmbTemplateDetailStore.
* @param {UmbControllerHostInterface} host
* @memberof UmbTemplateDetailStore
*/
constructor(host: UmbControllerHostInterface) {
super(host, UmbTemplateDetailStore.name);
}
/**
* Append a template to the store
* @param {Template} template
* @memberof UmbTemplateDetailStore
*/
append(template: Template) {
this.#data.append([template]);
}
/**
* Removes templates in the store with the given uniques
* @param {string[]} uniques
* @memberof UmbTemplateDetailStore
*/
remove(uniques: string[]) {
this.#data.remove(uniques);
}