91

Your question is basically the same as "should linked list items have a reference to the previous item?", and the answer is the same: it depends. There are use cases when a singly-linked list is correct, and there are use cases when a doubly-linked list is correct. The important point here is that it is the use case that matters, not the format: ...


9

Personally, I think the first pattern you showed to be a mistake. As you pointed out, it takes a lot of time to find the room. The general problem with the second pattern is that it makes reference counting garbage collection fail. (This issue varies by language.) What you missed is that there is a third pattern. Specifically, that the events to the ...


7

If you're doing this on a chat server application, then you should use a database. The most common database design for a tree is that parents do not have references to their children, only the child have foreign key reference to their parents. Instead, the parent to child relation should be handled by an index. If you're doing this in a chat client ...


4

In most tree models you want to know the parent of nodes, you will likely have a use case for it. You already mentioned your own use case and keeping track of parents is cheap so it is a no-brainer. In other tree applications you typically want the node to be able to tell you its path, and its level (or depth). For this you also need the parent. It is a ...


3

In general terms, you're adding an edge connecting Client and Room. If this is a real world example, this is a poor model to make it a parent-child relationship. As others have pointed out, you may have to extend it to multiple client-room relationships which breaks a single back-pointer from Child -> Room. This may seem wildly unrealistic but, say ...


3

You already listed two solutions - removing luxon, and removing date-fns - which are unacceptable to you. The simplest remaining option, as ugly as it is, would be to use both libraries side by side and accept the ugliness. Another (expensive) option would be to implement an API wrapper above luxon which provides date-fns compatibility, and let react-...


3

Undefined usually signifies that a property does not exist at all. For example, as you showed, attempting to access a missing property yields undefined. This is because the property itself does not exist; it is not valid. Null on the other hand signifies that a property exists, but has no value. If it is legal within your program for a value to be optionally ...


1

A mentioned in other answers already; what to do depends on the requirements. Add a link from the child back to the parent if you regularly and/or quickly need to be able to find the parent from the child. Don't add a link if there's no reason to, or if the cost of adding this link outweighs the benefit (e.g. additional resources used, additional code to ...


1

Trees are used for a variety of purposes, some of which are facilitated by having child nodes hold parent pointers, and some of which would require that child nodes not have parent pointers. If child nodes have references to their parents, than a reference to a child can effectively identify both a tree and location within it. On the other hand, making a ...


1

Your function getDoc maintains a list of outstanding requests. If the url is in that list then you wait for the running fetch to complete and the document to be saved, otherwise you add the URL to the list of outstanding requests And start the fetch. All nicely synchronised, please. The result might have a structure like this: const inFlight = {}; async ...


1

In the "Javascript world", there isn't one broadly accepted standard for folders and project hierarchies. But there are tons of frameworks for different purposes, and several of them impose a specific folder layout. So the best recommendation here I can give you here is: find a few other existing libs or frameworks of comparable size and / or ...


Only top voted, non community-wiki answers of a minimum length are eligible