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

[client] Optimize zustand stores #2687

Open
edisontim opened this issue Feb 10, 2025 · 1 comment · May be fixed by #2700
Open

[client] Optimize zustand stores #2687

edisontim opened this issue Feb 10, 2025 · 1 comment · May be fixed by #2700
Assignees

Comments

@edisontim
Copy link
Collaborator

I've noticed that we subscribe to the whole state in the subscriptions we do in the threeJS. A more optimized way would be to only subscribe to parts that interest us:

currently:

    useUIStore.subscribe(
      (state) => {
        console.log(state.structureEntityId);
        return state.previewBuilding;
      },
      (building) => {
        if (building) {
          this.buildingPreview?.setPreviewBuilding(building as any);
          this.highlightHexManager.highlightHexes(this.highlights);
        } else {
          this.clearBuildingMode();
        }
      },
    );
  }

but we could do it with subscribeWithSelector as explained here: https://stackoverflow.com/questions/78269060/how-to-subscribe-unsubscribe-to-a-zustand-nested-object-store

@portableDD
Copy link

May I take this issue on?

eta : 5 hours

@bob0005 bob0005 self-assigned this Feb 17, 2025
@bob0005 bob0005 linked a pull request Feb 21, 2025 that will close this issue
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 a pull request may close this issue.

3 participants