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

Serialize to indexdb #658

Merged
merged 34 commits into from
Oct 1, 2018
Merged

Serialize to indexdb #658

merged 34 commits into from
Oct 1, 2018

Conversation

captbaritone
Copy link
Owner

First stab at serializing state!

@captbaritone captbaritone requested a review from durasj September 19, 2018 00:15
@captbaritone
Copy link
Owner Author

I think all the right stuff is getting serialized now, but there are a few problems:

  1. When Winamp mounts, it tries to center itself, so the positioning data can get overwritten.
  2. We need to make sure that we respect the bounds of the current window size when reloading. Otherwise it's possible that we could serialize state in a very large window, and then reload in a very small window and have the Winamp windows be rendered all, or mostly, off screen.
  3. Serializing state where all the windows are closed is... bad. Basically makes the entire domain broken for the user forever since you can't really recover.

On that note, here's a link to this PR's build with the clearState flag set: https://deploy-preview-658--ecstatic-poincare-fe4c13.netlify.com/?clearState=1

Open that if you end up with bad serialized state.

@1j01
Copy link
Contributor

1j01 commented Sep 19, 2018

Going back and forth between /?clearState=1 and /, I found sometimes it moves the windows collectively down and to the right significantly (when at /), without the user having moved the windows.

Edit: and going back and forth between something other than ?clearState=1 so it doesn't clear it, or refreshing instead, it can get even further to the bottom right. With diminishing returns. It'll move half as much each time, until it reaches the bottom right.

@captbaritone
Copy link
Owner Author

@1j01 Okay, the issue where it fails to keep the same position across reloads has now been resolved, I believe.

Next before we ship this we need to ensure there is no way to leave the user in a state where a window is outside of their window.

@captbaritone
Copy link
Owner Author

Update: You now need the useState=1 flag to opt into persisting state to IndexDB:

https://deploy-preview-658--ecstatic-poincare-fe4c13.netlify.com/?useState=1

Copy link
Collaborator

@durasj durasj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty impressive stuff. Seems to work very well. I tried to do some quick smoke testing and created the #663. The only thing that doesn't seem to work is saving of the window positions. It used to work, but it seems to be broken now.

I've fixed the types and unified the code for the debounce and throttle. I'm not sure why are callbackArgs are defined in different scope, there doesn't seem to be any reason for that.

Btw. not sure if a mistake or not and I am really sorry for being "that guy", but it's an IndexedDB, not IndexDB. Just pointing it out to prevent some confusion in the future.

skinGenLetterWidths,
skinColors,
skinPlaylistStyle
} = state;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not hip like the destructuring, but could this simply return something like { doubled: state.doubled, ... } to get rid of the repetition?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, both options kinda suck. Even without the destructuring you still need to write every property twice. My, dubious, rational was that this way I didn't have to write state. n times, but... I'm not sure how important that is.

@@ -129,7 +138,27 @@ export default (media: Media) => (store: MiddlewareStore) => {
case SET_EQ_ON:
media.enableEq();
break;
case LOAD_SERIALIZED_STATE: {
// Set ALL THE THINGS!
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set ALL THE STATE

genWindows: Utils.objectMap(state.genWindows, w => ({
...w,
// Not sure why TypeScript can't figure this out for itself.
size: [0, 0] as [number, number]
Copy link
Collaborator

@durasj durasj Sep 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably caused by the "return type widening". Size type gets "widened" to number[]. Not sure how to work around this better than you did. Maybe it'll get eventually improved by the TS team. Seems there is a discussion for this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

@captbaritone
Copy link
Owner Author

Thanks for the correction re indexeddb. I think I've fixed the position serialization issue. I'm going to ship this now, but the serialization will be off by default.

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.

3 participants