Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Imagine you could share user data with JavaScript right in the browser. How would the code look like? This is what I came up with. Forks & comments much appreciated! (see also: https://gist.github.com/gr2m/5463475) #nobackend #dreamcode
// add a new share
share = new Share()
// grant / revoke access
share.grantReadAccess()
share.grantWriteAccess()
share.revokeReadAccess()
share.revokeWriteAccess()
share.grantReadAccess('joe@example.com')
share.revomeWriteAccess(['joe@example.com', 'lisa@example.com'])
// add all todo objects to the share
store.findAll('todo').then(share.add)
// remove a specific todo from the share
store.find('todo', '123').then(share.remove)
// remove objects from all shares
store.findAll('todo').then(share.remove)
// remove share
share.destroy()
// open a share and load all its objects
share = new Share('shareIdHere')
share.findAll().done( render )
// subscribe: sync changes between local store and remote share
share.subscribe()
share.unsubscribe()
aishwar commented Nov 15, 2013

This looks cool. I am curious how would shares work. Would a share just be an object that contains pointers to data objects? Or would the actual data object be copied into the share?

in a talk [1] someone from hoodie mentioned that they share the data using filtered replication of couchdb

[1] https://www.youtube.com/watch?v=-x3Q61dBAwk#t=1770

Owner
gr2m commented Jan 19, 2015

I've updated the code to be generic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment