|
// |
|
// INITIALIZE HOODIE |
|
// |
|
// The idea is, that one can use several Hoodie instances on the same page, |
|
// in order to interact with the different backends. |
|
// |
|
|
|
whereTheMagicHappens = 'https://yourapp.hood.ie' |
|
hoodie = new Hoodie(whereTheMagicHappens) |
|
|
|
|
|
// |
|
// ACCOUNT MODULE |
|
// |
|
// the hoodie.account module provides methods for common account related |
|
// tasks, like signing Up for a new account, resetting a password or changing |
|
// a username. |
|
// |
|
// All methods are asynchronous and return a promise. |
|
// |
|
|
|
hoodie.account.signUp('[email protected]', 'secret') |
|
hoodie.account.signIn('[email protected]', 'secret') |
|
hoodie.account.signOut() |
|
hoodie.account.changePassword('currentpassword', 'newpassword') |
|
hoodie.account.changeUsername('currentpassword', 'newusername') |
|
hoodie.account.resetPassword('[email protected]') |
|
hoodie.account.destroy('currentpassword') |
|
|
|
|
|
// |
|
// STORE MODULE |
|
// |
|
// the hoodie.store module provides methods to store and retrieve JSON objects. |
|
// It gets automatically synchronized when the user is signed in, so data stored |
|
// on one device is accessible on all devices by default. |
|
// |
|
// All methods are asynchronous and return a promise. |
|
// |
|
|
|
// store a new task |
|
type = 'task' |
|
attributes = {title: "remember the milk"} |
|
hoodie.store.add(type, attributes ).done ( function(newObject) { } ) |
|
|
|
// update an existing task |
|
type = 'task' |
|
id = 'abc4567' |
|
update = {size: 2} |
|
hoodie.store.update( type, id, update ).done ( function(updatedObject) { } ) |
|
|
|
// find a specific task |
|
type = 'task' |
|
id = 'abc4567' |
|
hoodie.store.find( type, id ).done ( function(object) { } ) |
|
|
|
// Load all tasks |
|
type = 'task' |
|
hoodie.store.findAll( type ).done ( function(objects) { } ) |
|
|
|
// remove an existing task |
|
type = 'task' |
|
id = 'abc4567' |
|
hoodie.store.remove( type, id ).done ( function(removedObject) { } ) |
|
|
|
|
|
// |
|
// REMOTE MODULE |
|
// |
|
// Hoodie.Remote provides methods to interact with data that |
|
// is stored remotely and therefore need HTTP requests. |
|
// |
|
// To instantiate Hoodie.Remote, use hoodie.open( name ). |
|
// hoodie.remote is a special Hoodie.Remote instance that is already |
|
// connected to the user's remote database. |
|
// |
|
// Most methods are asynchronous and return a promise. |
|
// |
|
|
|
var remote = hoodie.open("public_charts") |
|
|
|
// find all objects of type = "track" |
|
remote.findAll('track').then( function(tracks) { /* ... */ }) |
|
remote.add("track", { title: "Hoodie Hoodie Hoodie!" }) |
|
|
|
// listen to changes on remote and react on newly added tracks |
|
remote.connect() |
|
remote.on("add:track", playNewTrack ) |
For the module system I wouldn't use an extra library. We could use this tiny extend script.