Skip to content

Commit

Permalink
changed namings
Browse files Browse the repository at this point in the history
  • Loading branch information
mstuder committed Feb 22, 2023
1 parent 6dab1b0 commit 22f02b9
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 60 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

\-

## v2023-02-22-1

Changes:

\-

## v2023-02-21-1

Changes:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "2023-02-21-1"
"version": "2023-02-22-1"
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -24,19 +24,19 @@ export class FluxUiTreeStateApi {

/**
* @private
* @param {FluxUiTreeStateService} service
* @param {TreeStateService} service
*/
constructor(service) {
this.#service = service;
}

/**
* @property {FluxUiTreeStatePublisherAdapter} fluxUiTreeStatePublisherAdapter
* @return {Promise<FluxUiTreeStateApi>}
* @return {Promise<FluxEcoUiTreeStateApi>}
*/
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))));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
*/
Expand All @@ -12,13 +12,13 @@ export class FluxUiTreeStateManagerAdapter {
}

/**
* @param {FluxUiTreeStatePublisher} fluxUiTreeStatePublisher
* @return {Promise<FluxUiTreeStateManagerAdapter>}
* @param {TreeStatePublisher} fluxUiTreeStatePublisher
* @return {Promise<FluxEcoUiTreeStateManagerAdapter>}
*/
static async new(
fluxUiTreeStatePublisher
) {
return new FluxUiTreeStateManagerAdapter(fluxUiTreeStatePublisher)
return new FluxEcoUiTreeStateManagerAdapter(fluxUiTreeStatePublisher)
}

async setState(idPath, newState) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {NodeNestedSet} from "../ValueObjects/NodeNestedSet.mjs";
import {NodeState} from "../ValueObjects/NodeState.mjs";

export class FluxUiTreeNodeEntity {
export class TreeNodeEntity {
/**
* @var {NodeNestedSet}
*/
Expand All @@ -21,22 +21,22 @@ 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);
node.setParent(this);
}

/**
* @param {FluxUiTreeNodeEntity} parent
* @param {TreeNodeEntity} parent
*/
setParent(parent) {
this.parent = parent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
*/
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class FluxUiTreeStateEventsRecorder {
export class TreeStateEventsRecorder {
/**
* @type {array}
*/
Expand All @@ -8,7 +8,7 @@ export class FluxUiTreeStateEventsRecorder {
}

static new() {
return new FluxUiTreeStateEventsRecorder();
return new TreeStateEventsRecorder();
}

recordEvent(event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export class FluxUiTreeStateManager {
export class TreeStateManager {
#stateManager;

constructor(stateManager) {
this.#stateManager = stateManager;
}

/**
* @return {Promise<FluxUiTreeStateManager>}
* @return {Promise<TreeStateManager>}
*/
static async new(
stateManager
) {
return new FluxUiTreeStateManager(stateManager)
return new TreeStateManager(stateManager)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
export class FluxUiTreeStatePublisher {
export class TreeStatePublisher {
#statePublisher;

constructor(statePublisher) {
this.#statePublisher = statePublisher;
}

/**
* @return {Promise<FluxUiTreeStatePublisher>}
* @return {Promise<TreeStatePublisher>}
*/
static async new(
statePublisher
) {
return new FluxUiTreeStatePublisher(statePublisher)
return new TreeStatePublisher(statePublisher)
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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}
*/
Expand All @@ -23,15 +23,15 @@ export class FluxUiTreeStateService {
}

/**
* @param {FluxUiTreeStatePublisher} fluxUiTreeStatePublisher
* @param {FluxUiTreeStateManager} fluxUiTreeDataStateManager
* @return {Promise<FluxUiTreeStateService>}
* @param {TreeStatePublisher} fluxUiTreeStatePublisher
* @param {TreeStateManager} fluxUiTreeDataStateManager
* @return {Promise<TreeStateService>}
*/
static async new(
fluxUiTreeStatePublisher,
fluxUiTreeDataStateManager
) {
return new FluxUiTreeStateService(fluxUiTreeStatePublisher, fluxUiTreeDataStateManager)
return new TreeStateService(fluxUiTreeStatePublisher, fluxUiTreeDataStateManager)
}

/**
Expand All @@ -40,8 +40,8 @@ export class FluxUiTreeStateService {
* @return {Promise<void>}
*/
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) {
Expand All @@ -57,9 +57,9 @@ export class FluxUiTreeStateService {
* @return {Promise<void>}
*/
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();
Expand All @@ -77,10 +77,10 @@ export class FluxUiTreeStateService {
* @return {Promise<void>}
*/
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();
Expand All @@ -95,9 +95,9 @@ export class FluxUiTreeStateService {
* @return {Promise<void>}
*/
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) {
Expand Down

0 comments on commit 22f02b9

Please sign in to comment.