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

Sync multiple tabs using localStorage #105

Closed
wants to merge 4 commits into from

Conversation

sidthekidder
Copy link

So this is the basic code to sync code editor value across multiple tabs. One caveat is that apparently when 'Code mode' is enabled, i.e. 'Block mode' is disabled, then realtime changes do not sync across tabs. (the text can't redraw itself like blocks do). So I set the Code mode to go into Block mode whenever it receives a localStorage update. Probably the performance is taking a hit - handler is executing twice every keystroke, so I want to improve it.
While the local-storage wrapper isn't so big, it is a new module (2 months old) and doesn't seem to add much benefit as local storage is well supported in browsers. Safari in incognito mode doesn't support it. ( http://ponyfoo.com/articles/cross-tab-communication )

/* block mode needs to be set to change editor value */
setPaneEditorBlockMode(pane, true);
dropletEditor.setValue_raw(localStorage.getItem('dropletEditorValue'));
}, false);
Copy link
Member

Choose a reason for hiding this comment

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

Neat that it works. Here is a list of some things to address:

  • Only sync with changes on other tabs that are at exactly the same program (same user, same filename).
  • Sync across modes. There's dropletEditor for block mode and just editor for text mode. Changing text in one more should sync up with blocks in the other mode.... maybe? Or maybe only if it actually parses? That's something to think about.
  • Maintain "dirty" bits etc correctly. So if text changes, the "save" button gets shown at the right time.
  • Consider syncing on every change, not only when the line-count changes.
  • If you want to reduce syncing, consider using a timer to limit the frequency of changes sent to localStorage.

@sidthekidder
Copy link
Author

I tried to address the last 3 points of your comments, they were insightful. Using setTimeout really coordinated well with syncing, but it seems to have failed some tests as a result.
I'll work on the first point (important one) and the tests too, but my exams are on so will be busy till the 13th.

@davidbau
Copy link
Member

davidbau commented Mar 9, 2015

No problem. Looks like applications aren't due until March 27.

David

On Mon, Mar 9, 2015 at 9:05 AM, Siddhartha Sahai notifications@github.com
wrote:

I tried to address the last 3 points of your comments, they were
insightful. Using setTimeout really coordinated well with syncing problems,
but it seems to have failed some genuine tests.
I'll work on the first point (important one) and the tests too, but my
exams are on so will be busy till the 13th.


Reply to this email directly or view it on GitHub
#105 (comment).

@sidthekidder
Copy link
Author

So added simple checks for matching user and file names (which get stored as json with the editor text when syncing).
Due to different editor on('change') code involving setTimeout, the Travis CI is failing. I don't understand the exact reason right now, apparently turtle.queue().length becomes 33 instead of 0 and the stop button doesn't show ($('#stop').length is 0). I guess I will have to examine setTimeout's usage closely to see why it changed those tests, and then also write a new one for testing sync.

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.

None yet

3 participants