diff --git a/CHANGELOG.md b/CHANGELOG.md index 91387e5..ca0685e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ \- +## v2023-02-22-1 + + Changes: + +\- + ## v2023-02-21-1 Changes: diff --git a/README.md b/README.md index 046c3a0..3fbf5c2 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,10 @@ The FluxUiTreeState API is responsible for creating and managing the state of tr # Usage ``` javascript -import { FluxUiTreeStateApi } from "./FluxUiTreeStateApi.js"; +import { FluxEcoUiTreeStateApi } from "./FluxEcoUiTreeStateApi.js"; // Initialize the API -const treeStateApi = await FluxUiTreeStateApi.new({ +const treeStateApi = await FluxEcoUiTreeStateApi.new({ publish: (subscriberId, oldState, newState) => { // Send state change notification console.log(`Notify ${subscriberId} about tree changes: ${JSON.stringify(oldState)} -> ${JSON.stringify(newState)}`); diff --git a/metadata.json b/metadata.json index c27b8ba..b68fd3c 100644 --- a/metadata.json +++ b/metadata.json @@ -1,3 +1,3 @@ { - "version": "2023-02-21-1" + "version": "2023-02-22-1" } diff --git a/src/Adapters/Api/FluxUiTreeStateApi.mjs b/src/Adapters/Api/FluxEcoUiTreeStateApi.mjs similarity index 74% rename from src/Adapters/Api/FluxUiTreeStateApi.mjs rename to src/Adapters/Api/FluxEcoUiTreeStateApi.mjs index fabed3f..3b0b055 100644 --- a/src/Adapters/Api/FluxUiTreeStateApi.mjs +++ b/src/Adapters/Api/FluxEcoUiTreeStateApi.mjs @@ -1,7 +1,7 @@ -import {FluxUiTreeStateService} from "../../Core/Ports/FluxUiTreeStateService.mjs"; -import {FluxUiTreeStateManager} from "../../Core/Ports/FluxUiTreeStateManager.mjs"; -import {FluxUiTreeStateManagerAdapter} from "../State/FluxUiTreeStateManagerAdapter.mjs"; -import {FluxUiTreeStatePublisher} from "../../Core/Ports/FluxUiTreeStatePublisher.mjs"; +import {TreeStateService} from "../../Core/Ports/TreeStateService.mjs"; +import {TreeStateManager} from "../../Core/Ports/TreeStateManager.mjs"; +import {FluxEcoUiTreeStateManagerAdapter} from "../State/FluxEcoUiTreeStateManagerAdapter.mjs"; +import {TreeStatePublisher} from "../../Core/Ports/TreeStatePublisher.mjs"; /** * @typedef {Object} FluxUiTreeStatePublisherAdapter @@ -13,9 +13,9 @@ import {FluxUiTreeStatePublisher} from "../../Core/Ports/FluxUiTreeStatePublishe /** * Creates and manages states of tree data * - * @type FluxUiTreeStateApi + * @type FluxEcoUiTreeStateApi */ -export class FluxUiTreeStateApi { +export class FluxEcoUiTreeStateApi { name = "flux-eco-ui-tree-state"; /** * @var {FluxUiTreeStateService} #service @@ -24,7 +24,7 @@ export class FluxUiTreeStateApi { /** * @private - * @param {FluxUiTreeStateService} service + * @param {TreeStateService} service */ constructor(service) { this.#service = service; @@ -32,11 +32,11 @@ export class FluxUiTreeStateApi { /** * @property {FluxUiTreeStatePublisherAdapter} fluxUiTreeStatePublisherAdapter - * @return {Promise} + * @return {Promise} */ static async new(fluxUiTreeStatePublisherAdapter) { - const fluxUiTreeStatePublisher = await FluxUiTreeStatePublisher.new(fluxUiTreeStatePublisherAdapter); - return new FluxUiTreeStateApi(await FluxUiTreeStateService.new(fluxUiTreeStatePublisher, await FluxUiTreeStateManager.new(await FluxUiTreeStateManagerAdapter.new(fluxUiTreeStatePublisher)))); + const fluxUiTreeStatePublisher = await TreeStatePublisher.new(fluxUiTreeStatePublisherAdapter); + return new FluxEcoUiTreeStateApi(await TreeStateService.new(fluxUiTreeStatePublisher, await TreeStateManager.new(await FluxEcoUiTreeStateManagerAdapter.new(fluxUiTreeStatePublisher)))); } /** diff --git a/src/Adapters/State/FluxUiTreeStateManagerAdapter.mjs b/src/Adapters/State/FluxEcoUiTreeStateManagerAdapter.mjs similarity index 68% rename from src/Adapters/State/FluxUiTreeStateManagerAdapter.mjs rename to src/Adapters/State/FluxEcoUiTreeStateManagerAdapter.mjs index c0e9179..5b2c210 100644 --- a/src/Adapters/State/FluxUiTreeStateManagerAdapter.mjs +++ b/src/Adapters/State/FluxEcoUiTreeStateManagerAdapter.mjs @@ -1,6 +1,6 @@ -import {FluxUiTreeStatePublisher} from "../../Core/Ports/FluxUiTreeStatePublisher.mjs"; +import {TreeStatePublisher} from "../../Core/Ports/TreeStatePublisher.mjs"; -export class FluxUiTreeStateManagerAdapter { +export class FluxEcoUiTreeStateManagerAdapter { /** * @var {FluxUiTreeStatePublisher} */ @@ -12,13 +12,13 @@ export class FluxUiTreeStateManagerAdapter { } /** - * @param {FluxUiTreeStatePublisher} fluxUiTreeStatePublisher - * @return {Promise} + * @param {TreeStatePublisher} fluxUiTreeStatePublisher + * @return {Promise} */ static async new( fluxUiTreeStatePublisher ) { - return new FluxUiTreeStateManagerAdapter(fluxUiTreeStatePublisher) + return new FluxEcoUiTreeStateManagerAdapter(fluxUiTreeStatePublisher) } async setState(idPath, newState) { diff --git a/src/Core/Domain/Entities/FluxUiTreeNodeEntity.mjs b/src/Core/Domain/Entities/TreeNodeEntity.mjs similarity index 84% rename from src/Core/Domain/Entities/FluxUiTreeNodeEntity.mjs rename to src/Core/Domain/Entities/TreeNodeEntity.mjs index edea712..e97aee0 100644 --- a/src/Core/Domain/Entities/FluxUiTreeNodeEntity.mjs +++ b/src/Core/Domain/Entities/TreeNodeEntity.mjs @@ -1,7 +1,7 @@ import {NodeNestedSet} from "../ValueObjects/NodeNestedSet.mjs"; import {NodeState} from "../ValueObjects/NodeState.mjs"; -export class FluxUiTreeNodeEntity { +export class TreeNodeEntity { /** * @var {NodeNestedSet} */ @@ -21,14 +21,14 @@ export class FluxUiTreeNodeEntity { /** * @param {NodeNestedSet} nodeNestedSet * @param {NodeState} nodeState - * @return {FluxUiTreeNodeEntity} + * @return {TreeNodeEntity} */ static new(nodeNestedSet, nodeState) { - return new FluxUiTreeNodeEntity(nodeNestedSet, nodeState); + return new TreeNodeEntity(nodeNestedSet, nodeState); } /** - * @param {FluxUiTreeNodeEntity} node + * @param {TreeNodeEntity} node */ addChild(node) { this.children.set(node.nodeNestedSet.id, node); @@ -36,7 +36,7 @@ export class FluxUiTreeNodeEntity { } /** - * @param {FluxUiTreeNodeEntity} parent + * @param {TreeNodeEntity} parent */ setParent(parent) { this.parent = parent; diff --git a/src/Core/Domain/FluxUiTreeStateAggregate.mjs b/src/Core/Domain/TreeStateAggregate.mjs similarity index 87% rename from src/Core/Domain/FluxUiTreeStateAggregate.mjs rename to src/Core/Domain/TreeStateAggregate.mjs index 8435b83..08d33ba 100644 --- a/src/Core/Domain/FluxUiTreeStateAggregate.mjs +++ b/src/Core/Domain/TreeStateAggregate.mjs @@ -2,13 +2,13 @@ import {TreeCreatedEvent} from "./Events/TreeCreatedEvent.mjs"; import {NodeNestedSet} from "./ValueObjects/NodeNestedSet.mjs"; import {NodeState} from "./ValueObjects/NodeState.mjs"; import {Id} from "./ValueObjects/Id.mjs"; -import {FluxUiTreeNodeEntity} from "./Entities/FluxUiTreeNodeEntity.mjs"; +import {TreeNodeEntity} from "./Entities/TreeNodeEntity.mjs"; import {TreeState} from "./ValueObjects/TreeState.mjs"; import {NodeAppendedEvent} from "./Events/NodeAppendedEvent.mjs"; import {NodeStateStatus} from "./ValueObjects/NodeStateStatus.mjs"; import {NodeChangedEvent} from "./Events/NodeChangedEvent.mjs"; -export class FluxUiTreeStateAggregate { +export class TreeStateAggregate { /** * {EventRecorder} */ @@ -28,7 +28,7 @@ export class FluxUiTreeStateAggregate { this.nodeDataSchema = nodeDataSchema; const rootNestedSet = NodeNestedSet.new(rootNode.id.value, 1, 2); - this.rootNodeEntity = FluxUiTreeNodeEntity.new(rootNestedSet, rootNode); + this.rootNodeEntity = TreeNodeEntity.new(rootNestedSet, rootNode); this.nodeEntityMap = new Map(); this.deletedNodes = new Set(); @@ -39,26 +39,26 @@ export class FluxUiTreeStateAggregate { } /** - * @param {FluxUiTreeStateEventsRecorder} eventRecorder + * @param {TreeStateEventsRecorder} eventRecorder * @param {string} id * @param {object} nodeDataSchema - * @return {FluxUiTreeStateAggregate} + * @return {TreeStateAggregate} */ static create(eventRecorder, id, nodeDataSchema) { const treeId = Id.newTreeId(id); const nodeId = Id.newRootNodeId(); - const obj = new FluxUiTreeStateAggregate(eventRecorder, treeId, nodeDataSchema, NodeState.newRootNode(treeId, nodeId)) + const obj = new TreeStateAggregate(eventRecorder, treeId, nodeDataSchema, NodeState.newRootNode(treeId, nodeId)) obj.#eventRecorder.recordEvent(TreeCreatedEvent.new(obj.getState())) return obj; } /** - * @param {FluxUiTreeStateEventsRecorder} eventRecorder + * @param {TreeStateEventsRecorder} eventRecorder * @param {TreeState} treeState * @param treeState - * @return {FluxUiTreeStateAggregate} + * @return {TreeStateAggregate} */ static async fromState(eventRecorder, treeState) { const id = treeState.id; @@ -67,7 +67,7 @@ export class FluxUiTreeStateAggregate { const nodeStates = treeState.nodes; - const aggregate = new FluxUiTreeStateAggregate(eventRecorder, id, nodeDataSchema, rootNode) + const aggregate = new TreeStateAggregate(eventRecorder, id, nodeDataSchema, rootNode) for (const [nodeId, nodeState] of Object.entries(nodeStates)) { if (!nodeState) { @@ -92,7 +92,7 @@ export class FluxUiTreeStateAggregate { * @param {string} nodeId * @param {object} nodeData * @param {boolean} expanded - * @return {FluxUiTreeStateAggregate} + * @return {TreeStateAggregate} */ async appendNodeToRoot(nodeId, nodeData, expanded) { const rootNodeId = Id.newRootNodeId(); @@ -108,7 +108,7 @@ export class FluxUiTreeStateAggregate { * @param {string} nodeId * @param {object} nodeData * @param {boolean} expanded - * @return {FluxUiTreeStateAggregate} + * @return {TreeStateAggregate} */ async appendNodeToParentNode(parentNodeId, nodeId, nodeData, expanded) { const parentNodeEntity = this.nodeEntityMap.get(parentNodeId); @@ -132,7 +132,7 @@ export class FluxUiTreeStateAggregate { } const left = parentNodeEntity.nodeNestedSet.right; const right = left + 1; - const nodeEntity = FluxUiTreeNodeEntity.new(NodeNestedSet.new(nodeState.id.value, left, right), nodeState); + const nodeEntity = TreeNodeEntity.new(NodeNestedSet.new(nodeState.id.value, left, right), nodeState); parentNodeEntity.addChild(nodeEntity); await this.nodeEntityMap.set(nodeState.id.value, nodeEntity); diff --git a/src/Core/Domain/FluxUiTreeStateEventsRecorder.mjs b/src/Core/Domain/TreeStateEventsRecorder.mjs similarity index 76% rename from src/Core/Domain/FluxUiTreeStateEventsRecorder.mjs rename to src/Core/Domain/TreeStateEventsRecorder.mjs index 63cad26..c401ca3 100644 --- a/src/Core/Domain/FluxUiTreeStateEventsRecorder.mjs +++ b/src/Core/Domain/TreeStateEventsRecorder.mjs @@ -1,4 +1,4 @@ -export class FluxUiTreeStateEventsRecorder { +export class TreeStateEventsRecorder { /** * @type {array} */ @@ -8,7 +8,7 @@ export class FluxUiTreeStateEventsRecorder { } static new() { - return new FluxUiTreeStateEventsRecorder(); + return new TreeStateEventsRecorder(); } recordEvent(event) { diff --git a/src/Core/Ports/FluxUiTreeStateManager.mjs b/src/Core/Ports/TreeStateManager.mjs similarity index 80% rename from src/Core/Ports/FluxUiTreeStateManager.mjs rename to src/Core/Ports/TreeStateManager.mjs index cf860be..20d5665 100644 --- a/src/Core/Ports/FluxUiTreeStateManager.mjs +++ b/src/Core/Ports/TreeStateManager.mjs @@ -1,4 +1,4 @@ -export class FluxUiTreeStateManager { +export class TreeStateManager { #stateManager; constructor(stateManager) { @@ -6,12 +6,12 @@ export class FluxUiTreeStateManager { } /** - * @return {Promise} + * @return {Promise} */ static async new( stateManager ) { - return new FluxUiTreeStateManager(stateManager) + return new TreeStateManager(stateManager) } /** diff --git a/src/Core/Ports/FluxUiTreeStatePublisher.mjs b/src/Core/Ports/TreeStatePublisher.mjs similarity index 84% rename from src/Core/Ports/FluxUiTreeStatePublisher.mjs rename to src/Core/Ports/TreeStatePublisher.mjs index 5696630..2831bbb 100644 --- a/src/Core/Ports/FluxUiTreeStatePublisher.mjs +++ b/src/Core/Ports/TreeStatePublisher.mjs @@ -1,4 +1,4 @@ -export class FluxUiTreeStatePublisher { +export class TreeStatePublisher { #statePublisher; constructor(statePublisher) { @@ -6,12 +6,12 @@ export class FluxUiTreeStatePublisher { } /** - * @return {Promise} + * @return {Promise} */ static async new( statePublisher ) { - return new FluxUiTreeStatePublisher(statePublisher) + return new TreeStatePublisher(statePublisher) } /** diff --git a/src/Core/Ports/FluxUiTreeStateService.mjs b/src/Core/Ports/TreeStateService.mjs similarity index 72% rename from src/Core/Ports/FluxUiTreeStateService.mjs rename to src/Core/Ports/TreeStateService.mjs index b4638df..06953b7 100644 --- a/src/Core/Ports/FluxUiTreeStateService.mjs +++ b/src/Core/Ports/TreeStateService.mjs @@ -1,10 +1,10 @@ -import {FluxUiTreeStateEventsRecorder} from "../Domain/FluxUiTreeStateEventsRecorder.mjs"; -import {FluxUiTreeStateAggregate} from "../Domain/FluxUiTreeStateAggregate.mjs"; +import {TreeStateEventsRecorder} from "../Domain/TreeStateEventsRecorder.mjs"; +import {TreeStateAggregate} from "../Domain/TreeStateAggregate.mjs"; import {Id} from "../Domain/ValueObjects/Id.mjs"; -import {FluxUiTreeStateManager} from "./FluxUiTreeStateManager.mjs"; -import {FluxUiTreeStatePublisher} from "./FluxUiTreeStatePublisher.mjs"; +import {TreeStateManager} from "./TreeStateManager.mjs"; +import {TreeStatePublisher} from "./TreeStatePublisher.mjs"; -export class FluxUiTreeStateService { +export class TreeStateService { /** * @var {FluxUiTreeStatePublisher} */ @@ -23,15 +23,15 @@ export class FluxUiTreeStateService { } /** - * @param {FluxUiTreeStatePublisher} fluxUiTreeStatePublisher - * @param {FluxUiTreeStateManager} fluxUiTreeDataStateManager - * @return {Promise} + * @param {TreeStatePublisher} fluxUiTreeStatePublisher + * @param {TreeStateManager} fluxUiTreeDataStateManager + * @return {Promise} */ static async new( fluxUiTreeStatePublisher, fluxUiTreeDataStateManager ) { - return new FluxUiTreeStateService(fluxUiTreeStatePublisher, fluxUiTreeDataStateManager) + return new TreeStateService(fluxUiTreeStatePublisher, fluxUiTreeDataStateManager) } /** @@ -40,8 +40,8 @@ export class FluxUiTreeStateService { * @return {Promise} */ async createTree(treeId, nodeDataSchema) { - const eventRecorder = FluxUiTreeStateEventsRecorder.new(); - const aggregate = FluxUiTreeStateAggregate.create(eventRecorder, treeId, nodeDataSchema); + const eventRecorder = TreeStateEventsRecorder.new(); + const aggregate = TreeStateAggregate.create(eventRecorder, treeId, nodeDataSchema); const recordedEvents = eventRecorder.getRecordedEvents(); if (recordedEvents.length > 0) { @@ -57,9 +57,9 @@ export class FluxUiTreeStateService { * @return {Promise} */ async appendNodeToRoot(treeId, nodeId, nodeData, expanded) { - const eventRecorder = FluxUiTreeStateEventsRecorder.new(); + const eventRecorder = TreeStateEventsRecorder.new(); const treeState = await this.#fluxUiTreeStateManager.getState(Id.newTreeId(treeId).path); - const aggregate = await FluxUiTreeStateAggregate.fromState(eventRecorder, treeState); + const aggregate = await TreeStateAggregate.fromState(eventRecorder, treeState); await aggregate.appendNodeToRoot(nodeId, nodeData, expanded); const recordedEvents = eventRecorder.getRecordedEvents(); @@ -77,10 +77,10 @@ export class FluxUiTreeStateService { * @return {Promise} */ async appendNodeToParentNode(treeId, parentNodeId, nodeId, nodeData, expanded = false) { - const eventRecorder = FluxUiTreeStateEventsRecorder.new(); + const eventRecorder = TreeStateEventsRecorder.new(); const treeState = await this.#fluxUiTreeStateManager.getState(Id.newTreeId(treeId).path); - const aggregate = await FluxUiTreeStateAggregate.fromState(eventRecorder, treeState); + const aggregate = await TreeStateAggregate.fromState(eventRecorder, treeState); await aggregate.appendNodeToParentNode(parentNodeId, nodeId, nodeData, expanded) const recordedEvents = eventRecorder.getRecordedEvents(); @@ -95,9 +95,9 @@ export class FluxUiTreeStateService { * @return {Promise} */ async toggleNodeStatusExpanded(treeId, nodeId) { - const eventRecorder = FluxUiTreeStateEventsRecorder.new(); + const eventRecorder = TreeStateEventsRecorder.new(); const treeState = await this.#fluxUiTreeStateManager.getState(Id.newTreeId(treeId).path); - const aggregate = await FluxUiTreeStateAggregate.fromState(eventRecorder, treeState); + const aggregate = await TreeStateAggregate.fromState(eventRecorder, treeState); await aggregate.toggleNodeStatusExpanded(nodeId); const recordedEvents = eventRecorder.getRecordedEvents(); if (recordedEvents.length > 0) {