Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP use joined room optimization (DON'T USE – not functional) #150

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from

Conversation

GabrielCTroia
Copy link
Collaborator

No description provided.

…e joinedRoom updates

I learned a few things during these and came up with some ideas for future but as it is
right now it breaks stuff so DON'T USE. I REPEAT, DONT USE! :)

Here's what I've lerned:

// This isn't Optimal as it gets recreated each time
// while the premise of redux is to only update the slices that have actually changed
// That means that only touch the actual slices that have changed by value
// and leave the old references in palce so they don't trigger rerenders!
// Also, this is why flattening the data structure works and deep structures don't,
//  because when you update a deep structure the whole object has to update for even the
//  deepest value, but if things are flat (on the same level) then they don't their
// reference doesn't change and so they don't have to update!
const createActivity = (room: Room, activity: BaseRoomActivity) => {
  const peersList = Object.values(room.peersIncludingMe);
  const membersList = peersList.map(toRoomMember);

  return toRoomActivity(activity, membersList);
};

Also, see the comments here:

useEffect(() => {
    setJoinedRoom((prev) => {
      if (!roomAndActivityZip) {
        return undefined;
      }

      // If there is no prev, create it for the 1st time
      if (!prev) {
        return createJoinedRoom(roomAndActivityZip);
      }

      // If only the activity has changed, then you can just apply that
      // TODO: Maybe there's a need for a deeper (smarter) comparison
      if (roomAndActivityZip.activity !== prev.currentActivity) {
        return {
          ...prev,
          currentActivity: createActivity(roomAndActivityZip.room, roomAndActivityZip.activity),
        };
      }

      // If the current activity isn't the new one then the room has to be!
      // In case of the room just recreate the whole thing, for now, because
      //   the current activity heavily depends on it
      return createJoinedRoom(roomAndActivityZip);
    });
  }, [roomAndActivityZip]);
@GabrielCTroia GabrielCTroia changed the title Wip use joined room optimization WIP use joined room optimization (DON'T USE – not functional) Oct 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant