[MUSIC PLAYING]
GREG KNOKE: Hi, my name's Greg Knoke.
I'm the Google Drive developer relations technical writer and
with me today is--
STEVE BAZYL: Steve Bazyl, I've been here before of course.
GREG KNOKE: And today we're going to talk to about about a
new feature we launched for the real-time API.
We've recently added an undo and redo feature to the API.
That makes it really easy to implement this feature for
your own applications.
And I think the best way to demonstrate this is to jump
right into a live demonstration on my screen.
So, if you'll bear with me.
STEVE BAZYL: Go ahead.
GREG KNOKE: So right now on my screen, what you can see is we
have the realtime quickstart that you've
possibly seen before.
It's part of our documentation.
And I have two accounts live on the quickstart.
So you'll notice we have our standard text area and at the
bottom we've added these new Undo and Redo buttons.
So if you look here I'll type in a little bit of text here,
and you can see that now the Undo button has become
highlighted for only one these screens.
That's because these are two separate accounts.
So on the other account you can see
that Undo is not active.
That's because the Undo button only undoes local changes.
So you can see if I go back to my other
account, undo a few changes.
It's synchronized between both, but only one account can
actually undo.
Now if I go to the other account, type a little bit,
you'll see that if I undo changes here, I'm still
undoing only the changes made by that account.
So this handles all the complexity of what can happen
with undo and redo features in a collaborative environment,
but the code itself is very, very simple to implement.
And if you want to see how we implemented this for this
specific example, go ahead and take a look at the Google Apps
Developer Blog.
And you can also take a look at the realtime quickstart in
the Drive documentation.
And to show off a little bit more about this feature and
how it works with more complicated operations, I'll
hop over to Steve and he'll take a look at a realtime
tasks application he put together.
STEVE BAZYL: So this is one of the demos that we put together
with Realtime API few weeks back.
It's based on [INAUDIBLE].
And the difference between this and the QuickStart is the
data model's a little bit more complicated in this one.
It's a list of tasks and tasks have statuses.
And we can also do things like bulk operations.
Things like selecting all of the tasks and
marking them completed.
When we do things like that that we want to be one logical
operation from an undo and redo perspective.
And to do that, there is part of the API in the realtime.
API is this notion of compound operations and within a block
of code you can just say begin compound operation, make a
whole bunch of changes, and then when you're
done, say end operation.
And from an undo and redo perspective, those things are
then treated as a single operation on the stack.
So you can see this, actually if you can for the demo just
do a select all on everything and
then try a clear completed.
If we undo that, what you see is
everything just gets restored.
If we didn't do the compound operation, what would happen
in this case is everything would get cleared in one
operation, but if we tried to undo them, they would all be
undone individually.
Which is really not what would be expected from a user
perspective.
So it's really easy to do.
I actually just did the code for this yesterday.
It took me about, probably about five minutes to add
undo-redo support.
Probably the hardest part was figuring out
where to put the buttons.
But the code for this is really trivial and you can see
this on GitHub, Google Drive / realtime Tasks and
just check it out.
It's really, really simple.
There are some weird cases with this.
One of the things I want to show in the QuickStart is some
weird cases that can happen around conflicting changes.
So Greg, I think you had discovered this the other day.
An interesting case where you could have an undo, which is
effectively turns into a no-op.
GREG KNOKE: Right.
So for example in this case, if I undo or if I type the
word test one account and delete in the other account
and then undo those and then retype, I can't remember
exactly, and then try to undo it, you'll see it takes a
while before undo actually starts to do anything.
That's because when trying to undo words that the one
account is typed and then they'd been deleted, the undo
turns into a no-op.
So you can't undo typing a letter
that since been deleted.
STEVE BAZYL: Right, and this is actually the same as even
if you take out the concept of undo.
If you were to type into a range, in a list, or a string
that another collaborator deleted that range.
When those changes get resolved and transformed, that
is a no-op operation because you're deleting into an area
of text that doesn't exist anymore.
When those inserts or deletes or transformed, you're
effectively into the same situation.
So even though it's a little bit odd from a user
perspective, when you start to think about how the underlying
technology works and transformations, it actually
does make some sense.
There's probably somethings you can do to probably make
this a little bit easier for users and developers.
We had an idea of maybe like fast forwarding a little bit.
Trying to find things that are actually undo able.
But it is as it is now, it's predictable, it's consistent
with the way that regular inserts work today.
GREG KNOKE: Thanks again for tuning in for this Google
Developers Live and if you want to see how we implemented
any of the code in the QuickStart start or the
realtime tasks application, go ahead and check out our code
repo on GitHub and also look at the Google Apps developer
log and the Drive documentation.
STEVE BAZYL: And of course you can always ask us questions on
Stack Overflow or on the Google Drive Developers
Community and we're always happy to talk more about the
realtime API and of course hear that you're building.
GREG KNOKE: All right, well thank you again.
STEVE BAZYL: All right, see you guys next week.
[MUSIC PLAYING]