Last active
August 29, 2015 14:05
-
-
Save humphd/e505d219a19dedbfc649 to your computer and use it in GitHub Desktop.
MakeDrive Client API Example
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
// MakeDrive API - https://github.com/mozilla/makedrive | |
var MakeDrive = require('./path/to/makedrive.js'); | |
// fs API - https://github.com/js-platform/filer#filer | |
var fs = MakeDrive.fs(); | |
// Use fs right away, with or without network | |
fs.mkdir('/project', function(err) { | |
if(err) throw err; | |
fs.writeFile('/project/index.html', '<p>Hello World!</p>', function(err) { | |
if(err) throw err; | |
// /project/index.html is now written to disk | |
}); | |
}); | |
// When you want to sync, get the fs' sync object | |
var sync = fs.sync; | |
// Listen for events you care about | |
sync.on('error', function(err) { | |
// There was an error during syncing | |
}); | |
sync.on('connected', function() { | |
// Connected to sync server | |
}); | |
sync.on('disconnected', function() { | |
// Disconnected from sync server | |
}); | |
sync.on('syncing', function() { | |
// Syncing with server | |
}); | |
sync.on('completed', function() { | |
// Completed syncing with server | |
}); | |
// Connect to the server | |
sync.connect('ws://server-url.com'); | |
// [Optional, if in manual mode] Request an upstream sync with the server | |
sync.request(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment