Exploring the world of Angular and RxJS is a new adventure for me. Currently, I am working on developing an Angular component that facilitates multiple objects sharing a tree-structured dataset.
Let's dive into my scenario in a fictional yet simplified manner - creating an Angular component to transmit an entire company structure to the server. This structure comprises various "StuffDto" objects that reference each other as their managers, while all staff members share a common departmental hierarchy map within the company.
The intricate multi-level hierarchy map resembles:
- Marketing Dept
- Sales Dept
- In-store Sales Team
- On-site Sales Team
- Advertisement Dept
- Planner Team
- Designer Team
- Sales Dept
- Manufacturing Dept
- R&D Dept
- Engineer Team
- Researcher Team
- QA Dept
- Inspector Team
- Assurance Team
- R&D Dept
Presenting the StaffDto
class which will undergo direct submission to the server upon completion.
export class StaffDto {
id: string;
name: string;
assignedDept?: string;
managerId?: string;
}
Introducing the Stuff
object that will circulate through my Angular applications.
export class Stuff {
data: StuffDto;
_manager: Stuff;
get manager(): Stuff {
return this._manager;
}
set manager(manager: Stuff) {
this._manager = manager;
this.data.managerId = manager.data.id;
}
}
This setup functions seamlessly in certain scenarios, however not in all cases.
Suppose I create Peter and Tom, then designate Peter as Tom's manager. Below are the representations of the 2 StuffDto
objects.
{ id: abc01,
name: 'Peter',
assignedDept: 'Marketing Dept',
managerId: null }
{ id: abc02,
name: 'Tom',
assignedDept: 'Sales Dept',
managerId: 'abc01' }
If I modify Peter's id
from "abc01" to "abc01a", I anticipate Tom's ManagerId
to automatically update as well. Similarly, alternation of Peter's assignedDept
from "Marketing Dept" to "R&D Dept" should result in nullifying Tom's assignedDept
, as there exists no "Sales Dept" beneath Peter's new department.
I am uncertain if this can be achieved through RxJS subscription. Though I attempted converting _manager
into a Subject
and subscribing to it, the function solely triggers upon assigning a new manager, neglecting changes in the manager's properties.
An inquiry lingers - is there a solution without extensive code alterations? Since the StuffDto
is communicated to the server, modifications directly impacting it are out of the question.