DEV Community

Kevin Jump
Kevin Jump

Posted on

Early Adopter's guide to Umbraco v14 [Trees] - Stores

Inbetween our datasource- that is maintaing the tree state, so if for example if someone changes the name of item in the editor, the tree name will be updated.

Code for these posts is avalible in our TimeDashboard Repository FrontEnd (typescript) & Backend (c#)

Datastore.

our data store, again will inherit from an Umbraco based store UmbUniqueTreeStore which allows us to build a tree as long as we have a unique property on our classes.

export class TimeTreeStore extends UmbUniqueTreeStore {

    constructor(host: UmbControllerHostElement) {
        super(host, TIME_TREE_STORE_CONTEXT.toString());

        new UmbStoreConnector<TimeTreeItemModel, TimeTreeDetailModel>(
            host,
            this,
            TIME_TREE_STORE_CONTEXT,
            (item) => this.#createTreeMapper(item),
            (item) => this.#updateTreeItemMapper(item)
        )
    }

    #createTreeMapper = (item: TimeTreeDetailModel) => {
        const treeItem: TimeTreeItemModel = {
            unique: item.unique,
            parentUnique: null,
            name: item.name,
            entityType: item.entityType,
            isFolder: false,
            hasChildren: false
        };

        return treeItem;
    };

    #updateTreeItemMapper = (model: TimeTreeDetailModel) => {
        return {
            name: model.name
        };
    };
}
Enter fullscreen mode Exit fullscreen mode

The store allows us to map from the "tree item model", to a "details model". a tree item has enough information on it to render the treee node.

The detail model has the information that would be used by the workspace to show the main page of information to the user.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay