forked from josephg/ShareJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
# This script watches for changes in a document and constantly resaves a file | |||
# with the document's contents. | |||
|
|||
#client = require('share').client | |||
client = require('../src').client | |||
fs = require('fs') | |||
|
|||
argv = require('optimist') | |||
.usage('Usage: $0 -d docname [--url URL] [-f filename]') | |||
.default('d', 'hello') | |||
.default('url', 'http://localhost:8000/sjs') | |||
.argv | |||
|
|||
filename = argv.f || argv.d | |||
|
|||
console.log "Opening '#{argv.d}' at #{argv.url}. Saving to '#{filename}'" | |||
|
|||
timeout = null | |||
doc = null | |||
|
|||
# Writes the snapshot data to the file not more than once per second. | |||
write = -> | |||
if (timeout == null) | |||
timeout = setTimeout -> | |||
console.log "Saved version " + doc.version | |||
fs.writeFile filename, doc.snapshot | |||
timeout = null | |||
, 1000 | |||
|
|||
client.open argv.d, 'text', argv.url, (d, error) -> | |||
doc = d | |||
console.log('Document ' + argv.d + ' open at version ' + doc.version) | |||
|
|||
write() | |||
doc.on 'change', (op) -> | |||
write() |
This file was deleted.
Oops, something went wrong.