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

create preferencesStorage.js #737

Open
zepumph opened this issue Jul 23, 2021 · 13 comments
Open

create preferencesStorage.js #737

zepumph opened this issue Jul 23, 2021 · 13 comments

Comments

@zepumph
Copy link
Member

zepumph commented Jul 23, 2021

From phetsims/chipper#1042 (comment), @jessegreenberg and I want to create a way to store preferences with localStorage when possible.

We discussed how to do this for quite some time, with a few options.

  1. We could have preferencesStorage be more like a model for all preferences Properties, and initialize it with those Properties. Then the "view" could use preferencesStorage.xProperty in its components. We didn't like this because it seemed like a code smell to have to have all preferences Properties in the same file. There are a bunch of types of Properties for preferences. Audio/General/voicing/visual etc. In the view these are modular, so why cram them all into the same file in the model?
  2. We could have preferencesStorage just hard coded to mutate the same Properties that the view does. This duplicates these Properties, and is harder to maintain.
  3. What we would like to do: Create preferencesStorage.register() which is called within the preferences UI to mark a Property as something that should support this local storage feature.

Good luck us!

@zepumph
Copy link
Member Author

zepumph commented Jul 23, 2021

Another nice part about our strategy is that we can gracefully add in what we want to support as we go. From phetsims/chipper#1042 all I care about most is the three voicing levels checkboxes and the speech rate. That is where I will begin with this experiementation.

@zepumph
Copy link
Member Author

zepumph commented Jul 23, 2021

@zepumph
Copy link
Member Author

zepumph commented Aug 11, 2021

@jessegreenberg, here is a start. Can you review, and also think/add any others that you may be wanting here.

Should we add this to phetmarks?

@zepumph
Copy link
Member Author

zepumph commented Aug 12, 2021

There seems to be something still out of sync here. I'm unsure what it is. I'll keep taking a look. Perhaps preferencesStrorage.register cannot be so "late" in the startup sequence: in the view where used in the Preferences panel. I'll see what the trouble is first though.

@zepumph
Copy link
Member Author

zepumph commented Aug 23, 2021

There seems to be something still out of sync here. I'm unsure what it is. I'll keep taking a look. Perhaps preferencesStrorage.register cannot be so "late" in the startup sequence: in the view where used in the Preferences panel. I'll see what the trouble is first though.

This is caused because the PreferencesDialog is created lazily, thus the PreferencesStorage registration is also done lazily. @jessegreenberg, I think we may need to create a more central, "model-like" spot to register the preferences we have. Then pass that object to the view. What do you think?

@zepumph
Copy link
Member Author

zepumph commented Aug 27, 2021

@jessegreenberg and I discussed this, and we feel like creating a more base-level "PreferencesModel" is the way to go. This will house all the Properties used by the view so that the view doesn't sprinkle in dependencies. It also allows for a single place where PreferencesStorage can register Properties. This seems much more prudent to me.

We discussed briefly the though of just creating the dialog on startup, but didn't like forcing that to support PreferencesStorage. It also didn't seem very MVC.

We will refactor in #743, and then come back here to register things.

@zepumph
Copy link
Member Author

zepumph commented Aug 27, 2021

@jessegreenberg will let me know when this is ready for further work.

@zepumph zepumph assigned jessegreenberg and unassigned zepumph Aug 27, 2021
zepumph added a commit that referenced this issue Dec 2, 2021
@zepumph
Copy link
Member Author

zepumph commented Dec 2, 2021

Added rate and pitch above to greatly increase my productivity while testing. It adds to the list that would be refactored into a PreferencesModel, but not too horribly I think.

@zepumph
Copy link
Member Author

zepumph commented Mar 2, 2022

Added interactiveHighlights property above.

I have made some progress in #743, it would be good to touch base with @jessegreenberg in this issue to see if he ever uses ?preferencesStorage, and what he would like to see improved on it.

@zepumph
Copy link
Member Author

zepumph commented Jul 26, 2022

Ok. I updated this to house more Properties that PreferencesModel supports. Please review. Is there anything else you'd like here?

@jessegreenberg
Copy link
Contributor

This is great, thank you! I am loving this feature. There was a TODO that I just removed about where to put PreferencesStorage.register calls. I think now that we only have PreferencesModel they are great where they are.

Ready to close?

@zepumph
Copy link
Member Author

zepumph commented Aug 29, 2022

I wonder if we should add any more to preferencesStorage? Also I wonder if customPreferences properties that are getting linked should be stored here. Perhaps via an option? I'll take a look.

@zepumph
Copy link
Member Author

zepumph commented Sep 1, 2022

I'm wondering if we can figure out a way to combine the function to link phet-io elements and register for preferences storage. I'll think about it.

@zepumph zepumph removed their assignment Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants